diff --git a/detekt-baseline.xml b/detekt-baseline.xml index 929a06f..a4c99bc 100644 --- a/detekt-baseline.xml +++ b/detekt-baseline.xml @@ -2,40 +2,19 @@ - FunctionNaming:Dsl.kt$@UUIDExperimentalAPI public fun UUIDv7(timeStamp: Instant = Clock.System.now(), random: Random = SecureRandom): UUID - FunctionNaming:UUID7.kt$@UUIDExperimentalAPI public fun UUIDv7(timeStamp: Long, random: Random = SecureRandom): UUID - MagicNumber:Encoding.kt$0xff - MagicNumber:Encoding.kt$56 - MagicNumber:Encoding.kt$7 - MagicNumber:Encoding.kt$8 - MagicNumber:Formatter.kt$0xffff - MagicNumber:Formatter.kt$0xffffffffffffL - MagicNumber:Formatter.kt$10 - MagicNumber:Formatter.kt$16 - MagicNumber:Formatter.kt$32 - MagicNumber:Formatter.kt$38 - MagicNumber:Formatter.kt$4 - MagicNumber:Formatter.kt$48 - MagicNumber:Formatter.kt$6 - MagicNumber:Formatter.kt$8 - MagicNumber:Formatter.kt$9 + FunctionNaming:Dsl.kt$public fun UUIDv7(timeStamp: Instant = Clock.System.now(), random: Random): Uuid + FunctionNaming:UUID7.kt$public fun UUIDv7(timeStamp: Long, random: Random): Uuid MagicNumber:KotlinConfig.kt$8 MagicNumber:NameBasedGenerator.kt$0x3f MagicNumber:NameBasedGenerator.kt$4 MagicNumber:NameBasedGenerator.kt$6 MagicNumber:NameBasedGenerator.kt$8 - MagicNumber:Parser.kt$10 - MagicNumber:Parser.kt$12 - MagicNumber:Parser.kt$16 - MagicNumber:Parser.kt$32 - MagicNumber:Parser.kt$4 - MagicNumber:Parser.kt$48 - MagicNumber:Parser.kt$6 - MagicNumber:Parser.kt$8 - MagicNumber:RandomGenerator.kt$0x38 - MagicNumber:RandomGenerator.kt$0x3fffffffffffffffL - MagicNumber:RandomGenerator.kt$0x4000L - MagicNumber:RandomGenerator.kt$0x80L + MagicNumber:RandomGenerator.kt$0x3f + MagicNumber:RandomGenerator.kt$0x40 + MagicNumber:RandomGenerator.kt$0x80 + MagicNumber:RandomGenerator.kt$16 + MagicNumber:RandomGenerator.kt$6 + MagicNumber:RandomGenerator.kt$8 MagicNumber:SHA1.kt$SHA1$0X67452301 MagicNumber:SHA1.kt$SHA1$0x5a827999 MagicNumber:SHA1.kt$SHA1$0x6ed9eba1 @@ -65,37 +44,31 @@ MagicNumber:SHA1.kt$SHA1.IntArrayView$3 MagicNumber:SHA1.kt$SHA1.IntArrayView$4 MagicNumber:SHA1.kt$SHA1.IntArrayView$8 - MagicNumber:SecureRandom.js.kt$SecureRandomBrowser$31 - MagicNumber:SecureRandom.js.kt$SecureRandomBrowser$32 - MagicNumber:UUID.kt$UUID$0x0fffL - MagicNumber:UUID.kt$UUID$0x1fff - MagicNumber:UUID.kt$UUID$0xf000L - MagicNumber:UUID.kt$UUID$0xffff0000L - MagicNumber:UUID.kt$UUID$0xffffffffffffL - MagicNumber:UUID.kt$UUID$12 - MagicNumber:UUID.kt$UUID$13 - MagicNumber:UUID.kt$UUID$15 - MagicNumber:UUID.kt$UUID$16 - MagicNumber:UUID.kt$UUID$32 - MagicNumber:UUID.kt$UUID$4 - MagicNumber:UUID.kt$UUID$48 - MagicNumber:UUID.kt$UUID$5 - MagicNumber:UUID.kt$UUID$60 - MagicNumber:UUID.kt$UUID$61 - MagicNumber:UUID.kt$UUID$7 - MagicNumber:UUID.kt$UUID.Version.NAME_BASED_MD5$3 - MagicNumber:UUID.kt$UUID.Version.NAME_BASED_SHA1$5 - MagicNumber:UUID.kt$UUID.Version.RANDOM_BASED$4 + MagicNumber:UUID.kt$0x0fffL + MagicNumber:UUID.kt$0x1fff + MagicNumber:UUID.kt$0xf000L + MagicNumber:UUID.kt$0xffff00000000L + MagicNumber:UUID.kt$0xffff0000L + MagicNumber:UUID.kt$0xffffffffffffL + MagicNumber:UUID.kt$12 + MagicNumber:UUID.kt$13 + MagicNumber:UUID.kt$15 + MagicNumber:UUID.kt$16 + MagicNumber:UUID.kt$32 + MagicNumber:UUID.kt$4 + MagicNumber:UUID.kt$48 + MagicNumber:UUID.kt$5 + MagicNumber:UUID.kt$60 + MagicNumber:UUID.kt$61 + MagicNumber:UUID.kt$7 + MagicNumber:UUID7.kt$0x0fffL + MagicNumber:UUID7.kt$0xffff0000L MagicNumber:UUID7.kt$16 MagicNumber:UUID7.kt$28672 + MagicNumber:UUID7.kt$32 MagicNumber:UUID7.kt$4095 + MagicNumber:UUID7.kt$48 MagicNumber:UUID7.kt$62 - MatchingDeclarationName:CommonParcelable.apple.kt$CommonParcelable - MatchingDeclarationName:CommonParcelable.js.kt$CommonParcelable - MatchingDeclarationName:CommonParcelable.jvm.kt$CommonParcelable - MatchingDeclarationName:CommonParcelable.linux.kt$CommonParcelable - MatchingDeclarationName:CommonParcelable.ming.kt$CommonParcelable TooManyFunctions:SHA1.kt$SHA1 - VariableNaming:UUID7.kt$val rand_a = helper.timeStamp and 4095 diff --git a/gradle/build-logic/build.gradle.kts b/gradle/build-logic/build.gradle.kts index 4202fa6..4ee0950 100644 --- a/gradle/build-logic/build.gradle.kts +++ b/gradle/build-logic/build.gradle.kts @@ -4,7 +4,6 @@ plugins { dependencies { implementation(libs.plugins.kotlin.jvm.toDep()) - implementation(libs.plugins.kotlin.serialization.toDep()) implementation(libs.plugins.kotlin.parcelize.toDep()) implementation(libs.plugins.android.toDep()) implementation(libs.plugins.binary.toDep()) diff --git a/gradle/build-logic/src/main/kotlin/KotlinConfig.kt b/gradle/build-logic/src/main/kotlin/KotlinConfig.kt index 1578b43..86fe3f2 100644 --- a/gradle/build-logic/src/main/kotlin/KotlinConfig.kt +++ b/gradle/build-logic/src/main/kotlin/KotlinConfig.kt @@ -8,7 +8,7 @@ fun KotlinProjectExtension.kotlinConfig() { sourceSets.configureEach { languageSettings { progressiveMode = true - optIn("kotlinx.uuid.InternalAPI") + optIn("kotlin.uuid.ExperimentalUuidApi") } } } diff --git a/gradle/build-logic/src/main/kotlin/kotlinJvm.gradle.kts b/gradle/build-logic/src/main/kotlin/kotlinJvm.gradle.kts deleted file mode 100644 index d87aca3..0000000 --- a/gradle/build-logic/src/main/kotlin/kotlinJvm.gradle.kts +++ /dev/null @@ -1,8 +0,0 @@ -plugins { - kotlin("jvm") - kotlin("plugin.serialization") -} - -kotlin { - kotlinConfig() -} diff --git a/gradle/build-logic/src/main/kotlin/kotlinMPP.gradle.kts b/gradle/build-logic/src/main/kotlin/kotlinMPP.gradle.kts index 2570e61..a947124 100644 --- a/gradle/build-logic/src/main/kotlin/kotlinMPP.gradle.kts +++ b/gradle/build-logic/src/main/kotlin/kotlinMPP.gradle.kts @@ -1,6 +1,5 @@ plugins { kotlin("multiplatform") - kotlin("plugin.serialization") } kotlin { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e8dcdd0..40176a4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,6 @@ [versions] -kotlin = "2.0.0" +kotlin = "2.0.20-RC2" serialization = "1.7.1" -exposed = "0.52.0" [libraries] serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" } @@ -9,11 +8,6 @@ serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-jso serialization-cbor = { module = "org.jetbrains.kotlinx:kotlinx-serialization-cbor", version.ref = "serialization" } serialization-protobuf = { module = "org.jetbrains.kotlinx:kotlinx-serialization-protobuf", version.ref = "serialization" } -exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exposed" } -exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" } -h2 = { module = "com.h2database:h2", version = "2.3.230" } -slf4j = { module = "org.slf4j:slf4j-simple", version = "2.0.13" } - sqldelight-runtime = { module = "app.cash.sqldelight:runtime", version = "2.0.2" } datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version = "0.6.0" } diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index f4858df..a1c4cee 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -282,10 +282,10 @@ accepts@~1.3.4: mime-types "~2.1.34" negotiator "0.6.3" -acorn-import-assertions@^1.9.0: - version "1.9.0" - resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz#507276249d684797c84e0734ef84860334cfb1ac" - integrity sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA== +acorn-import-attributes@^1.9.5: + version "1.9.5" + resolved "https://registry.yarnpkg.com/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz#7eb1557b1ba05ef18b5ed0ec67591bfab04688ef" + integrity sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ== acorn@^8.7.1: version "8.8.2" @@ -312,10 +312,10 @@ ajv@^6.12.5: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ansi-colors@4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" - integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== +ansi-colors@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.3.tgz#37611340eb2243e70cc604cad35d63270d48781b" + integrity sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw== ansi-regex@^5.0.1: version "5.0.1" @@ -397,7 +397,7 @@ braces@^3.0.2, braces@~3.0.2: dependencies: fill-range "^7.0.1" -browser-stdout@1.3.1: +browser-stdout@^1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== @@ -448,7 +448,7 @@ chalk@^4.1.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chokidar@3.5.3, chokidar@^3.5.1: +chokidar@^3.5.1: version "3.5.3" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== @@ -463,6 +463,21 @@ chokidar@3.5.3, chokidar@^3.5.1: optionalDependencies: fsevents "~2.3.2" +chokidar@^3.5.3: + version "3.6.0" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.6.0.tgz#197c6cc669ef2a8dc5e7b4d97ee4e092c3eb0d5b" + integrity sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw== + dependencies: + anymatch "~3.1.2" + braces "~3.0.2" + glob-parent "~5.1.2" + is-binary-path "~2.1.0" + is-glob "~4.0.1" + normalize-path "~3.0.0" + readdirp "~3.6.0" + optionalDependencies: + fsevents "~2.3.2" + chrome-trace-event@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz#1015eced4741e15d06664a957dbbf50d041e26ac" @@ -572,13 +587,20 @@ debug@2.6.9: dependencies: ms "2.0.0" -debug@4.3.4, debug@^4.3.4, debug@~4.3.1, debug@~4.3.2: +debug@^4.3.4, debug@~4.3.1, debug@~4.3.2: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== dependencies: ms "2.1.2" +debug@^4.3.5: + version "4.3.6" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.6.tgz#2ab2c38fbaffebf8aa95fdfe6d88438c7a13c52b" + integrity sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg== + dependencies: + ms "2.1.2" + decamelize@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837" @@ -599,10 +621,10 @@ di@^0.0.1: resolved "https://registry.yarnpkg.com/di/-/di-0.0.1.tgz#806649326ceaa7caa3306d75d985ea2748ba913c" integrity sha512-uJaamHkagcZtHPqCIHZxnFrXlunQXgBOsZSUOWwFw31QJCAbyTBoHMW75YOTur5ZNx8pIeAKgf6GWIgaqqiLhA== -diff@5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b" - integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== +diff@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-5.2.0.tgz#26ded047cd1179b78b9537d5ef725503ce1ae531" + integrity sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A== dom-serialize@^2.2.1: version "2.2.1" @@ -655,10 +677,10 @@ engine.io@~6.5.2: engine.io-parser "~5.2.1" ws "~8.11.0" -enhanced-resolve@^5.16.0: - version "5.16.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.16.0.tgz#65ec88778083056cb32487faa9aef82ed0864787" - integrity sha512-O+QWCviPNSSLAD9Ucn8Awv+poAkqn3T1XY5/N7kR7rQO9yfSGWkYZDwpJ+iKF7B8rxaQKWngSqACpgzeapSyoA== +enhanced-resolve@^5.17.0: + version "5.17.1" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz#67bfbbcc2f81d511be77d686a90267ef7f898a15" + integrity sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" @@ -688,7 +710,7 @@ escape-html@~1.0.3: resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" integrity sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow== -escape-string-regexp@4.0.0: +escape-string-regexp@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== @@ -768,14 +790,6 @@ finalhandler@1.1.2: statuses "~1.5.0" unpipe "~1.0.0" -find-up@5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" - integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== - dependencies: - locate-path "^6.0.0" - path-exists "^4.0.0" - find-up@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" @@ -784,6 +798,14 @@ find-up@^4.0.0: locate-path "^5.0.0" path-exists "^4.0.0" +find-up@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" + integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== + dependencies: + locate-path "^6.0.0" + path-exists "^4.0.0" + flat@^5.0.2: version "5.0.2" resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" @@ -854,17 +876,6 @@ glob-to-regexp@^0.4.1: resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== -glob@8.1.0: - version "8.1.0" - resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" - integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^5.0.1" - once "^1.3.0" - glob@^7.1.3, glob@^7.1.7: version "7.2.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" @@ -877,6 +888,17 @@ glob@^7.1.3, glob@^7.1.7: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^5.0.1" + once "^1.3.0" + graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.11, graceful-fs@^4.2.4, graceful-fs@^4.2.6: version "4.2.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" @@ -899,7 +921,7 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" -he@1.2.0: +he@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== @@ -1041,7 +1063,7 @@ jest-worker@^27.4.5: merge-stream "^2.0.0" supports-color "^8.0.0" -js-yaml@4.1.0: +js-yaml@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== @@ -1154,7 +1176,7 @@ lodash@^4.17.15, lodash@^4.17.21: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== -log-symbols@4.1.0: +log-symbols@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== @@ -1200,13 +1222,6 @@ mime@^2.5.2: resolved "https://registry.yarnpkg.com/mime/-/mime-2.6.0.tgz#a2a682a95cd4d0cb1d6257e28f83da7e35800367" integrity sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg== -minimatch@5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.0.1.tgz#fb9022f7528125187c92bd9e9b6366be1cf3415b" - integrity sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g== - dependencies: - brace-expansion "^2.0.1" - minimatch@^3.0.4, minimatch@^3.1.1: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" @@ -1214,7 +1229,7 @@ minimatch@^3.0.4, minimatch@^3.1.1: dependencies: brace-expansion "^1.1.7" -minimatch@^5.0.1: +minimatch@^5.0.1, minimatch@^5.1.6: version "5.1.6" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== @@ -1240,31 +1255,31 @@ mkdirp@^0.5.5: dependencies: minimist "^1.2.6" -mocha@10.3.0: - version "10.3.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.3.0.tgz#0e185c49e6dccf582035c05fa91084a4ff6e3fe9" - integrity sha512-uF2XJs+7xSLsrmIvn37i/wnc91nw7XjOQB8ccyx5aEgdnohr7n+rEiZP23WkCYHjilR6+EboEnbq/ZQDz4LSbg== - dependencies: - ansi-colors "4.1.1" - browser-stdout "1.3.1" - chokidar "3.5.3" - debug "4.3.4" - diff "5.0.0" - escape-string-regexp "4.0.0" - find-up "5.0.0" - glob "8.1.0" - he "1.2.0" - js-yaml "4.1.0" - log-symbols "4.1.0" - minimatch "5.0.1" - ms "2.1.3" - serialize-javascript "6.0.0" - strip-json-comments "3.1.1" - supports-color "8.1.1" - workerpool "6.2.1" - yargs "16.2.0" - yargs-parser "20.2.4" - yargs-unparser "2.0.0" +mocha@10.7.0: + version "10.7.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.7.0.tgz#9e5cbed8fa9b37537a25bd1f7fb4f6fc45458b9a" + integrity sha512-v8/rBWr2VO5YkspYINnvu81inSz2y3ODJrhO175/Exzor1RcEZZkizgE2A+w/CAXXoESS8Kys5E62dOHGHzULA== + dependencies: + ansi-colors "^4.1.3" + browser-stdout "^1.3.1" + chokidar "^3.5.3" + debug "^4.3.5" + diff "^5.2.0" + escape-string-regexp "^4.0.0" + find-up "^5.0.0" + glob "^8.1.0" + he "^1.2.0" + js-yaml "^4.1.0" + log-symbols "^4.1.0" + minimatch "^5.1.6" + ms "^2.1.3" + serialize-javascript "^6.0.2" + strip-json-comments "^3.1.1" + supports-color "^8.1.1" + workerpool "^6.5.1" + yargs "^16.2.0" + yargs-parser "^20.2.9" + yargs-unparser "^2.0.0" ms@2.0.0: version "2.0.0" @@ -1276,7 +1291,7 @@ ms@2.1.2: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== -ms@2.1.3: +ms@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== @@ -1531,13 +1546,6 @@ schema-utils@^3.2.0: ajv "^6.12.5" ajv-keywords "^3.5.2" -serialize-javascript@6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" - integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== - dependencies: - randombytes "^2.1.0" - serialize-javascript@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.1.tgz#b206efb27c3da0b0ab6b52f48d170b7996458e5c" @@ -1545,6 +1553,13 @@ serialize-javascript@^6.0.1: dependencies: randombytes "^2.1.0" +serialize-javascript@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.2.tgz#defa1e055c83bf6d59ea805d8da862254eb6a6c2" + integrity sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g== + dependencies: + randombytes "^2.1.0" + setprototypeof@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424" @@ -1667,18 +1682,11 @@ strip-ansi@^6.0.0, strip-ansi@^6.0.1: dependencies: ansi-regex "^5.0.1" -strip-json-comments@3.1.1: +strip-json-comments@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== -supports-color@8.1.1, supports-color@^8.0.0: - version "8.1.1" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" - integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== - dependencies: - has-flag "^4.0.0" - supports-color@^7.1.0: version "7.2.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" @@ -1686,6 +1694,13 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +supports-color@^8.0.0, supports-color@^8.1.1: + version "8.1.1" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" + integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== + dependencies: + has-flag "^4.0.0" + supports-preserve-symlinks-flag@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" @@ -1744,10 +1759,10 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -typescript@5.4.3: - version "5.4.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff" - integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg== +typescript@5.5.4: + version "5.5.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" + integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== ua-parser-js@^0.7.30: version "0.7.35" @@ -1841,10 +1856,10 @@ webpack-sources@^3.2.3: resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== -webpack@5.91.0: - version "5.91.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.91.0.tgz#ffa92c1c618d18c878f06892bbdc3373c71a01d9" - integrity sha512-rzVwlLeBWHJbmgTC/8TvAcu5vpJNII+MelQpylD4jNERPwpBJOE2lEcko1zJX3QJeLjTTAnQxn/OJ8bjDzVQaw== +webpack@5.93.0: + version "5.93.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.93.0.tgz#2e89ec7035579bdfba9760d26c63ac5c3462a5e5" + integrity sha512-Y0m5oEY1LRuwly578VqluorkXbvXKh7U3rLoQCEO04M97ScRr44afGVkI0FQFsXzysk5OgFAxjZAb9rsGQVihA== dependencies: "@types/eslint-scope" "^3.7.3" "@types/estree" "^1.0.5" @@ -1852,10 +1867,10 @@ webpack@5.91.0: "@webassemblyjs/wasm-edit" "^1.12.1" "@webassemblyjs/wasm-parser" "^1.12.1" acorn "^8.7.1" - acorn-import-assertions "^1.9.0" + acorn-import-attributes "^1.9.5" browserslist "^4.21.10" chrome-trace-event "^1.0.2" - enhanced-resolve "^5.16.0" + enhanced-resolve "^5.17.0" es-module-lexer "^1.2.1" eslint-scope "5.1.1" events "^3.2.0" @@ -1890,10 +1905,10 @@ wildcard@^2.0.0: resolved "https://registry.yarnpkg.com/wildcard/-/wildcard-2.0.0.tgz#a77d20e5200c6faaac979e4b3aadc7b3dd7f8fec" integrity sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw== -workerpool@6.2.1: - version "6.2.1" - resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" - integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== +workerpool@^6.5.1: + version "6.5.1" + resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544" + integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA== wrap-ansi@^7.0.0: version "7.0.0" @@ -1919,17 +1934,12 @@ y18n@^5.0.5: resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== -yargs-parser@20.2.4: - version "20.2.4" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54" - integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA== - -yargs-parser@^20.2.2: +yargs-parser@^20.2.2, yargs-parser@^20.2.9: version "20.2.9" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== -yargs-unparser@2.0.0: +yargs-unparser@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb" integrity sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA== @@ -1939,7 +1949,7 @@ yargs-unparser@2.0.0: flat "^5.0.2" is-plain-obj "^2.1.0" -yargs@16.2.0, yargs@^16.1.1: +yargs@^16.1.1, yargs@^16.2.0: version "16.2.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== diff --git a/kotlinx-uuid-core/api/android/kotlinx-uuid-core.api b/kotlinx-uuid-core/api/android/kotlinx-uuid-core.api index 85dc776..e6c8bc0 100644 --- a/kotlinx-uuid-core/api/android/kotlinx-uuid-core.api +++ b/kotlinx-uuid-core/api/android/kotlinx-uuid-core.api @@ -1,130 +1,51 @@ public final class kotlinx/uuid/BinarySerializer : kotlinx/serialization/KSerializer { public static final field INSTANCE Lkotlinx/uuid/BinarySerializer; public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lkotlinx/uuid/UUID; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lkotlin/uuid/Uuid; public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lkotlinx/uuid/UUID;)V -} - -public final class kotlinx/uuid/EncodingKt { - public static final fun UUID ([B)Lkotlinx/uuid/UUID; - public static final fun UUID ([J)Lkotlinx/uuid/UUID; - public static final fun encodeToByteArray (Lkotlinx/uuid/UUID;)[B - public static final fun encodeToLongArray (Lkotlinx/uuid/UUID;)[J -} - -public abstract interface annotation class kotlinx/uuid/InternalAPI : java/lang/annotation/Annotation { -} - -public final class kotlinx/uuid/MigrationKt { - public static final fun clockSequence (Lkotlinx/uuid/UUID;)I - public static final fun fromString (Lkotlinx/uuid/UUID$Companion;Ljava/lang/String;)Lkotlinx/uuid/UUID; - public static final fun getLeastSignificantBits (Lkotlinx/uuid/UUID;)J - public static final fun getMostSignificantBits (Lkotlinx/uuid/UUID;)J - public static final fun nameUUIDFromBytes (Lkotlinx/uuid/UUID$Companion;[B)Lkotlinx/uuid/UUID; - public static final fun node (Lkotlinx/uuid/UUID;)J - public static final fun randomUUID (Lkotlinx/uuid/UUID$Companion;)Lkotlinx/uuid/UUID; - public static final fun timestamp (Lkotlinx/uuid/UUID;)J - public static final fun variant (Lkotlinx/uuid/UUID;)I - public static final fun version (Lkotlinx/uuid/UUID;)I + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lkotlin/uuid/Uuid;)V } public final class kotlinx/uuid/NameBasedGeneratorKt { - public static final fun generateUUID (Lkotlinx/uuid/UUID$Companion;Lkotlinx/uuid/UUID;Ljava/lang/String;)Lkotlinx/uuid/UUID; - public static final fun generateUUID (Lkotlinx/uuid/UUID$Companion;[B)Lkotlinx/uuid/UUID; + public static final fun generateUUID (Lkotlin/uuid/Uuid$Companion;Lkotlin/uuid/Uuid;Ljava/lang/String;)Lkotlin/uuid/Uuid; + public static final fun generateUUID (Lkotlin/uuid/Uuid$Companion;[B)Lkotlin/uuid/Uuid; } public final class kotlinx/uuid/RandomGeneratorKt { - public static final fun generateUUID (Lkotlinx/uuid/UUID$Companion;Lkotlin/random/Random;)Lkotlinx/uuid/UUID; - public static synthetic fun generateUUID$default (Lkotlinx/uuid/UUID$Companion;Lkotlin/random/Random;ILjava/lang/Object;)Lkotlinx/uuid/UUID; - public static final fun nextUUID (Lkotlin/random/Random;)Lkotlinx/uuid/UUID; -} - -public final class kotlinx/uuid/SecureRandom_androidKt { - public static final fun getSecureRandom ()Lkotlin/random/Random; + public static final fun nextUuid (Lkotlin/random/Random;)Lkotlin/uuid/Uuid; + public static final fun random (Lkotlin/uuid/Uuid$Companion;Lkotlin/random/Random;)Lkotlin/uuid/Uuid; } -public abstract class kotlinx/uuid/Serializer : kotlinx/serialization/KSerializer { - public synthetic fun (ZLkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lkotlinx/uuid/UUID; - public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lkotlinx/uuid/UUID;)V -} - -public final class kotlinx/uuid/Serializer$Default : kotlinx/uuid/Serializer { - public static final field INSTANCE Lkotlinx/uuid/Serializer$Default; -} - -public final class kotlinx/uuid/Serializer$WrappedCurlyBrackets : kotlinx/uuid/Serializer { - public static final field INSTANCE Lkotlinx/uuid/Serializer$WrappedCurlyBrackets; +public final class kotlinx/uuid/UUID7Kt { + public static final fun UUIDv7 (JLkotlin/random/Random;)Lkotlin/uuid/Uuid; + public static final fun getUnixTimeStamp (Lkotlin/uuid/Uuid;)J } -public final class kotlinx/uuid/UUID : android/os/Parcelable, java/lang/Comparable { - public static final field CREATOR Landroid/os/Parcelable$Creator; - public static final field Companion Lkotlinx/uuid/UUID$Companion; - public fun ()V - public fun (IJIJI)V - public synthetic fun (IJIJIILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun (Ljava/lang/String;)V - public fun (Lkotlinx/uuid/UUID$Version;JIJI)V - public synthetic fun (Lkotlinx/uuid/UUID$Version;JIJIILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun compareTo (Ljava/lang/Object;)I - public fun compareTo (Lkotlinx/uuid/UUID;)I - public final fun describeContents ()I +public final class kotlinx/uuid/UUIDKt { + public static final fun from (Lkotlin/uuid/Uuid$Companion;IJIJI)Lkotlin/uuid/Uuid; + public static synthetic fun from$default (Lkotlin/uuid/Uuid$Companion;IJIJIILjava/lang/Object;)Lkotlin/uuid/Uuid; + public static final fun getClockSequence (Lkotlin/uuid/Uuid;)I + public static final fun getNode (Lkotlin/uuid/Uuid;)J + public static final fun getTimeStamp (Lkotlin/uuid/Uuid;)J + public static final fun getVariant (Lkotlin/uuid/Uuid;)I + public static final fun getVersionNumber (Lkotlin/uuid/Uuid;)I + public static final fun isRfcVariant (Lkotlin/uuid/Uuid;)Z + public static final fun isValidUUIDString (Lkotlin/uuid/Uuid$Companion;Ljava/lang/String;)Z + public static final fun toUUIDOrNull (Ljava/lang/String;)Lkotlin/uuid/Uuid; + public static final fun toUuid (Ljava/lang/String;)Lkotlin/uuid/Uuid; +} + +public final class kotlinx/uuid/internal/UuidParceler : kotlinx/parcelize/Parceler { + public static final field INSTANCE Lkotlinx/uuid/internal/UuidParceler; + public synthetic fun create (Landroid/os/Parcel;)Ljava/lang/Object; + public fun create (Landroid/os/Parcel;)Lkotlin/uuid/Uuid; public fun equals (Ljava/lang/Object;)Z - public final fun getClockSequence ()I - public final fun getNode ()J - public final fun getTimeStamp ()J - public final fun getVariant ()I - public final fun getVersion ()Lkotlinx/uuid/UUID$Version; - public final fun getVersionNumber ()I public fun hashCode ()I - public final fun isRfcVariant ()Z - public fun toString ()Ljava/lang/String; - public final fun toString (Z)Ljava/lang/String; - public final fun writeToParcel (Landroid/os/Parcel;I)V -} - -public final class kotlinx/uuid/UUID$Companion { - public final fun getNIL ()Lkotlinx/uuid/UUID; - public final fun isValidUUIDString (Ljava/lang/String;)Z - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - -public final class kotlinx/uuid/UUID$Creator : android/os/Parcelable$Creator { - public fun ()V - public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object; - public final fun createFromParcel (Landroid/os/Parcel;)Lkotlinx/uuid/UUID; public synthetic fun newArray (I)[Ljava/lang/Object; - public final fun newArray (I)[Lkotlinx/uuid/UUID; -} - -public final class kotlinx/uuid/UUID$Version : java/lang/Enum { - public static final field DCE_SECURITY Lkotlinx/uuid/UUID$Version; - public static final field NAME_BASED_MD5 Lkotlinx/uuid/UUID$Version; - public static final field NAME_BASED_SHA1 Lkotlinx/uuid/UUID$Version; - public static final field RANDOM_BASED Lkotlinx/uuid/UUID$Version; - public static final field TIME_BASED Lkotlinx/uuid/UUID$Version; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lkotlinx/uuid/UUID$Version; - public static fun values ()[Lkotlinx/uuid/UUID$Version; -} - -public final class kotlinx/uuid/UUID7Kt { - public static final fun UUIDv7 (JLkotlin/random/Random;)Lkotlinx/uuid/UUID; - public static synthetic fun UUIDv7$default (JLkotlin/random/Random;ILjava/lang/Object;)Lkotlinx/uuid/UUID; - public static final fun getUnixTimeStamp (Lkotlinx/uuid/UUID;)J -} - -public abstract interface annotation class kotlinx/uuid/UUIDExperimentalAPI : java/lang/annotation/Annotation { - public abstract fun plannedVersion ()Ljava/lang/String; -} - -public final class kotlinx/uuid/UUIDKt { - public static final fun toUUID (Ljava/lang/String;)Lkotlinx/uuid/UUID; - public static final fun toUUIDOrNull (Ljava/lang/String;)Lkotlinx/uuid/UUID; + public fun newArray (I)[Lkotlin/uuid/Uuid; + public fun toString ()Ljava/lang/String; + public synthetic fun write (Ljava/lang/Object;Landroid/os/Parcel;I)V + public fun write (Lkotlin/uuid/Uuid;Landroid/os/Parcel;I)V } diff --git a/kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api b/kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api index 97d07cc..2597f01 100644 --- a/kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api +++ b/kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api @@ -1,127 +1,43 @@ public final class kotlinx/uuid/BinarySerializer : kotlinx/serialization/KSerializer { public static final field INSTANCE Lkotlinx/uuid/BinarySerializer; public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lkotlinx/uuid/UUID; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lkotlin/uuid/Uuid; public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lkotlinx/uuid/UUID;)V + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lkotlin/uuid/Uuid;)V } public final class kotlinx/uuid/ConvertingKt { - public static final fun toJavaUUID (Lkotlinx/uuid/UUID;)Ljava/util/UUID; - public static final fun toKotlinUUID (Ljava/util/UUID;)Lkotlinx/uuid/UUID; -} - -public final class kotlinx/uuid/EncodingKt { - public static final fun UUID ([B)Lkotlinx/uuid/UUID; - public static final fun UUID ([J)Lkotlinx/uuid/UUID; - public static final fun encodeToByteArray (Lkotlinx/uuid/UUID;)[B - public static final fun encodeToLongArray (Lkotlinx/uuid/UUID;)[J -} - -public abstract interface annotation class kotlinx/uuid/InternalAPI : java/lang/annotation/Annotation { -} - -public final class kotlinx/uuid/MigrationKt { - public static final fun clockSequence (Lkotlinx/uuid/UUID;)I - public static final fun fromString (Lkotlinx/uuid/UUID$Companion;Ljava/lang/String;)Lkotlinx/uuid/UUID; - public static final fun getLeastSignificantBits (Lkotlinx/uuid/UUID;)J - public static final fun getMostSignificantBits (Lkotlinx/uuid/UUID;)J - public static final fun nameUUIDFromBytes (Lkotlinx/uuid/UUID$Companion;[B)Lkotlinx/uuid/UUID; - public static final fun node (Lkotlinx/uuid/UUID;)J - public static final fun randomUUID (Lkotlinx/uuid/UUID$Companion;)Lkotlinx/uuid/UUID; - public static final fun timestamp (Lkotlinx/uuid/UUID;)J - public static final fun variant (Lkotlinx/uuid/UUID;)I - public static final fun version (Lkotlinx/uuid/UUID;)I + public static final fun toJavaUUID (Lkotlin/uuid/Uuid;)Ljava/util/UUID; + public static final fun toKotlinUuid (Ljava/util/UUID;)Lkotlin/uuid/Uuid; } public final class kotlinx/uuid/NameBasedGeneratorKt { - public static final fun generateUUID (Lkotlinx/uuid/UUID$Companion;Lkotlinx/uuid/UUID;Ljava/lang/String;)Lkotlinx/uuid/UUID; - public static final fun generateUUID (Lkotlinx/uuid/UUID$Companion;[B)Lkotlinx/uuid/UUID; + public static final fun generateUUID (Lkotlin/uuid/Uuid$Companion;Lkotlin/uuid/Uuid;Ljava/lang/String;)Lkotlin/uuid/Uuid; + public static final fun generateUUID (Lkotlin/uuid/Uuid$Companion;[B)Lkotlin/uuid/Uuid; } public final class kotlinx/uuid/RandomGeneratorKt { - public static final fun generateUUID (Lkotlinx/uuid/UUID$Companion;Lkotlin/random/Random;)Lkotlinx/uuid/UUID; - public static synthetic fun generateUUID$default (Lkotlinx/uuid/UUID$Companion;Lkotlin/random/Random;ILjava/lang/Object;)Lkotlinx/uuid/UUID; - public static final fun nextUUID (Lkotlin/random/Random;)Lkotlinx/uuid/UUID; -} - -public final class kotlinx/uuid/SecureRandomKt { - public static final fun getSecureRandom ()Lkotlin/random/Random; -} - -public abstract class kotlinx/uuid/Serializer : kotlinx/serialization/KSerializer { - public synthetic fun (ZLkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lkotlinx/uuid/UUID; - public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lkotlinx/uuid/UUID;)V -} - -public final class kotlinx/uuid/Serializer$Default : kotlinx/uuid/Serializer { - public static final field INSTANCE Lkotlinx/uuid/Serializer$Default; -} - -public final class kotlinx/uuid/Serializer$WrappedCurlyBrackets : kotlinx/uuid/Serializer { - public static final field INSTANCE Lkotlinx/uuid/Serializer$WrappedCurlyBrackets; -} - -public final class kotlinx/uuid/UUID : java/lang/Comparable, kotlinx/uuid/internal/CommonParcelable { - public static final field Companion Lkotlinx/uuid/UUID$Companion; - public fun ()V - public fun (IJIJI)V - public synthetic fun (IJIJIILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun (Ljava/lang/String;)V - public fun (Lkotlinx/uuid/UUID$Version;JIJI)V - public synthetic fun (Lkotlinx/uuid/UUID$Version;JIJIILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun compareTo (Ljava/lang/Object;)I - public fun compareTo (Lkotlinx/uuid/UUID;)I - public fun equals (Ljava/lang/Object;)Z - public final fun getClockSequence ()I - public final fun getNode ()J - public final fun getTimeStamp ()J - public final fun getVariant ()I - public final fun getVersion ()Lkotlinx/uuid/UUID$Version; - public final fun getVersionNumber ()I - public fun hashCode ()I - public final fun isRfcVariant ()Z - public fun toString ()Ljava/lang/String; - public final fun toString (Z)Ljava/lang/String; -} - -public final class kotlinx/uuid/UUID$Companion { - public final fun getNIL ()Lkotlinx/uuid/UUID; - public final fun isValidUUIDString (Ljava/lang/String;)Z - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - -public final class kotlinx/uuid/UUID$Version : java/lang/Enum { - public static final field DCE_SECURITY Lkotlinx/uuid/UUID$Version; - public static final field NAME_BASED_MD5 Lkotlinx/uuid/UUID$Version; - public static final field NAME_BASED_SHA1 Lkotlinx/uuid/UUID$Version; - public static final field RANDOM_BASED Lkotlinx/uuid/UUID$Version; - public static final field TIME_BASED Lkotlinx/uuid/UUID$Version; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lkotlinx/uuid/UUID$Version; - public static fun values ()[Lkotlinx/uuid/UUID$Version; + public static final fun nextUuid (Lkotlin/random/Random;)Lkotlin/uuid/Uuid; + public static final fun random (Lkotlin/uuid/Uuid$Companion;Lkotlin/random/Random;)Lkotlin/uuid/Uuid; } public final class kotlinx/uuid/UUID7Kt { - public static final fun UUIDv7 (JLkotlin/random/Random;)Lkotlinx/uuid/UUID; - public static synthetic fun UUIDv7$default (JLkotlin/random/Random;ILjava/lang/Object;)Lkotlinx/uuid/UUID; - public static final fun getUnixTimeStamp (Lkotlinx/uuid/UUID;)J -} - -public abstract interface annotation class kotlinx/uuid/UUIDExperimentalAPI : java/lang/annotation/Annotation { - public abstract fun plannedVersion ()Ljava/lang/String; + public static final fun UUIDv7 (JLkotlin/random/Random;)Lkotlin/uuid/Uuid; + public static final fun getUnixTimeStamp (Lkotlin/uuid/Uuid;)J } public final class kotlinx/uuid/UUIDKt { - public static final fun toUUID (Ljava/lang/String;)Lkotlinx/uuid/UUID; - public static final fun toUUIDOrNull (Ljava/lang/String;)Lkotlinx/uuid/UUID; -} - -public abstract interface class kotlinx/uuid/internal/CommonParcelable { + public static final fun from (Lkotlin/uuid/Uuid$Companion;IJIJI)Lkotlin/uuid/Uuid; + public static synthetic fun from$default (Lkotlin/uuid/Uuid$Companion;IJIJIILjava/lang/Object;)Lkotlin/uuid/Uuid; + public static final fun getClockSequence (Lkotlin/uuid/Uuid;)I + public static final fun getNode (Lkotlin/uuid/Uuid;)J + public static final fun getTimeStamp (Lkotlin/uuid/Uuid;)J + public static final fun getVariant (Lkotlin/uuid/Uuid;)I + public static final fun getVersionNumber (Lkotlin/uuid/Uuid;)I + public static final fun isRfcVariant (Lkotlin/uuid/Uuid;)Z + public static final fun isValidUUIDString (Lkotlin/uuid/Uuid$Companion;Ljava/lang/String;)Z + public static final fun toUUIDOrNull (Ljava/lang/String;)Lkotlin/uuid/Uuid; + public static final fun toUuid (Ljava/lang/String;)Lkotlin/uuid/Uuid; } diff --git a/kotlinx-uuid-core/build.gradle.kts b/kotlinx-uuid-core/build.gradle.kts index ea084b7..3d9e3f8 100644 --- a/kotlinx-uuid-core/build.gradle.kts +++ b/kotlinx-uuid-core/build.gradle.kts @@ -15,21 +15,13 @@ plugins { } kotlin { - applyDefaultHierarchyTemplate { - common { - group("linuxDerivat") { - group("androidNative") - group("linux") - } - } - } - sourceSets { commonMain { dependencies { implementation(libs.serialization.core) } } + commonTest { dependencies { implementation(kotlin("test")) @@ -80,8 +72,4 @@ kotlin { } } } - compilerOptions.freeCompilerArgs.addAll( - "-P", - "plugin:org.jetbrains.kotlin.parcelize:additionalAnnotation=kotlinx.uuid.internal.CommonParcelize", - ) } diff --git a/kotlinx-uuid-core/src/androidInstrumentedTest/kotlin/kotlinx/uuid/internal/ParcelableTest.kt b/kotlinx-uuid-core/src/androidInstrumentedTest/kotlin/kotlinx/uuid/internal/ParcelableTest.kt index 6c5c64f..d0abea6 100644 --- a/kotlinx-uuid-core/src/androidInstrumentedTest/kotlin/kotlinx/uuid/internal/ParcelableTest.kt +++ b/kotlinx-uuid-core/src/androidInstrumentedTest/kotlin/kotlinx/uuid/internal/ParcelableTest.kt @@ -1,17 +1,37 @@ package kotlinx.uuid.internal import android.os.Parcel +import android.os.Parcelable +import kotlinx.parcelize.Parcelize +import kotlinx.parcelize.TypeParceler import kotlinx.parcelize.parcelableCreator import kotlinx.uuid.* import kotlin.test.* +import kotlin.uuid.Uuid class ParcelableTest { @Test fun testParcelable() { val parcel = Parcel.obtain() - val uuid = UUID(SOME_UUID_STRING) - uuid.writeToParcel(parcel, uuid.describeContents()) + val uuid = Uuid.parse(SOME_UUID_STRING) + with(UuidParceler) { + uuid.write(parcel, 0) + } parcel.setDataPosition(0) - assertEquals(uuid, parcelableCreator().createFromParcel(parcel)) + assertEquals(uuid, UuidParceler.create(parcel)) } + + @Test + fun testBox() { + val parcel = Parcel.obtain() + val uuid = Uuid.parse(SOME_UUID_STRING) + val box = Box(uuid) + box.writeToParcel(parcel, 0) + parcel.setDataPosition(0) + assertEquals(Box(uuid), parcelableCreator().createFromParcel(parcel)) + } + + @Parcelize + @TypeParceler() + data class Box(val uuid: Uuid) : Parcelable } diff --git a/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/SecureRandom.android.kt b/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/SecureRandom.android.kt deleted file mode 100644 index 436a4d6..0000000 --- a/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/SecureRandom.android.kt +++ /dev/null @@ -1,13 +0,0 @@ -package kotlinx.uuid - -import kotlin.random.* - -/** - * Returns a platform dependent SecureRandom instance. - * - On JVM, it uses `java.util.SecureRandom` - * - On JS, it uses `window.crypto` or `nodejs.crypto`. - * - On darwin, it uses `SecRandomCopyBytes`. - * - On mingw, it uses `BCryptRandom`. - * - On Linux and Android native, it uses `DevUrandom`. - */ -public actual val SecureRandom: Random = java.security.SecureRandom().asKotlinRandom() diff --git a/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/internal/CommonParcelable.android.kt b/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/internal/CommonParcelable.android.kt deleted file mode 100644 index b0f1a52..0000000 --- a/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/internal/CommonParcelable.android.kt +++ /dev/null @@ -1,5 +0,0 @@ -package kotlinx.uuid.internal - -import android.os.* - -public actual typealias CommonParcelable = Parcelable diff --git a/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/internal/UuidParceler.kt b/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/internal/UuidParceler.kt new file mode 100644 index 0000000..46b102f --- /dev/null +++ b/kotlinx-uuid-core/src/androidMain/kotlin/kotlinx/uuid/internal/UuidParceler.kt @@ -0,0 +1,19 @@ +package kotlinx.uuid.internal + +import android.os.Parcel +import kotlinx.parcelize.Parceler +import kotlin.uuid.Uuid + +public data object UuidParceler : Parceler { + override fun create(parcel: Parcel): Uuid = Uuid.fromLongs( + parcel.readLong(), + parcel.readLong(), + ) + + override fun Uuid.write(parcel: Parcel, flags: Int) { + toLongs { mostSignificantBits, leastSignificantBits -> + parcel.writeLong(mostSignificantBits) + parcel.writeLong(leastSignificantBits) + } + } +} diff --git a/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/Converter.kt b/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/Converter.kt index 2238b98..2121eae 100644 --- a/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/Converter.kt +++ b/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/Converter.kt @@ -4,14 +4,16 @@ package kotlinx.uuid +import kotlin.uuid.Uuid + /** - * Converts this [platform.Foundation.NSUUID][platform.Foundation.NSUUID] value to a [kotlinx.uuid.UUID][UUID] value + * Converts this [platform.Foundation.NSUUID][platform.Foundation.NSUUID] value to a [kotlin.uuid.UUID][Uuid] value * by using the [UUIDString][platform.Foundation.NSUUID.UUIDString] representation. */ -public fun platform.Foundation.NSUUID.toKotlinUUID(): UUID = UUID(UUIDString) +public fun platform.Foundation.NSUUID.toKotlinUuid(): Uuid = Uuid.parse(UUIDString) /** - * Converts this [kotlinx.uuid.UUID][UUID] value to a [platform.Foundation.NSUUID][platform.Foundation.NSUUID] value + * Converts this [kotlin.uuid.Uuid][Uuid] value to a [platform.Foundation.NSUUID][platform.Foundation.NSUUID] value * by using the default [toString] representation. */ -public fun UUID.toNsUUID(): platform.Foundation.NSUUID = platform.Foundation.NSUUID(toString()) +public fun Uuid.toNsUUID(): platform.Foundation.NSUUID = platform.Foundation.NSUUID(toString()) diff --git a/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/SecureRandom.apple.kt b/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/SecureRandom.apple.kt deleted file mode 100644 index 2d89cdd..0000000 --- a/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/SecureRandom.apple.kt +++ /dev/null @@ -1,26 +0,0 @@ -package kotlinx.uuid - -import kotlinx.cinterop.* -import kotlinx.uuid.internal.* -import platform.Security.* -import platform.darwin.* -import kotlin.random.* - -public actual val SecureRandom: Random = SecureRandomIos - -/** - * https://developer.apple.com/documentation/security/1399291-secrandomcopybytes?language=objc - */ -@OptIn(ExperimentalForeignApi::class) -private object SecureRandomIos : Random() { - @OptIn(UnsafeNumber::class) - override fun nextBits(bitCount: Int): Int { - require(bitCount > 0) - val numberOfBytes = (bitCount + Byte.SIZE_BITS) / Byte.SIZE_BITS - val bytes = ByteArray(size = numberOfBytes) - val status = SecRandomCopyBytes(kSecRandomDefault, numberOfBytes.convert(), bytes.refTo(0)) - - require(status == errSecSuccess) - return bytes.toInt() - } -} diff --git a/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/internal/CommonParcelable.apple.kt b/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/internal/CommonParcelable.apple.kt deleted file mode 100644 index 76c06b9..0000000 --- a/kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/internal/CommonParcelable.apple.kt +++ /dev/null @@ -1,3 +0,0 @@ -package kotlinx.uuid.internal - -public actual interface CommonParcelable diff --git a/kotlinx-uuid-core/src/appleTest/kotlin/kotlinx/uuid/NsUUIDConvertingTest.kt b/kotlinx-uuid-core/src/appleTest/kotlin/kotlinx/uuid/NsUUIDConvertingTest.kt index ebcc0a4..6bad1d6 100644 --- a/kotlinx-uuid-core/src/appleTest/kotlin/kotlinx/uuid/NsUUIDConvertingTest.kt +++ b/kotlinx-uuid-core/src/appleTest/kotlin/kotlinx/uuid/NsUUIDConvertingTest.kt @@ -9,12 +9,13 @@ package kotlinx.uuid import kotlin.test.* +import kotlin.uuid.Uuid class NsUUIDConvertingTest { @Test fun toNsUUID() { - val kotlinUUID = UUID(SOME_UUID_STRING) + val kotlinUUID = Uuid.parse(SOME_UUID_STRING) val nsUUID = kotlinUUID.toNsUUID() assertEquals(SOME_UUID_STRING, nsUUID.UUIDString.lowercase()) } @@ -22,7 +23,7 @@ class NsUUIDConvertingTest { @Test fun fromNsUUID() { val nsUUID = platform.Foundation.NSUUID(SOME_UUID_STRING) - val kotlinUUID = nsUUID.toKotlinUUID() + val kotlinUUID = nsUUID.toKotlinUuid() assertEquals(SOME_UUID_STRING, kotlinUUID.toString()) } } diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/BinarySerializer.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/BinarySerializer.kt index ed7aaa3..52a08c1 100644 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/BinarySerializer.kt +++ b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/BinarySerializer.kt @@ -8,6 +8,7 @@ import kotlinx.serialization.* import kotlinx.serialization.builtins.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.* +import kotlin.uuid.Uuid /** * This serializer is useful with binary formats to reduce size. You may also use it with @@ -21,21 +22,23 @@ import kotlinx.serialization.encoding.* * Cbor.encodeToByteArray(BinarySerializer, myUUID) * ``` */ -public object BinarySerializer : KSerializer { +public object BinarySerializer : KSerializer { private val serializer = LongArraySerializer() override val descriptor: SerialDescriptor = serializer.descriptor - override fun serialize(encoder: Encoder, value: UUID) { - encoder.encodeSerializableValue(serializer, value.encodeToLongArray()) + override fun serialize(encoder: Encoder, value: Uuid) { + value.toLongs { mostSignificantBits, leastSignificantBits -> + encoder.encodeSerializableValue(serializer, longArrayOf(mostSignificantBits, leastSignificantBits)) + } } - override fun deserialize(decoder: Decoder): UUID { + override fun deserialize(decoder: Decoder): Uuid { return decoder.decodeSerializableValue(serializer).let { array -> if (array.size != 2) { throw SerializationException("UUID array should consist of 2 elements") } - UUID(array) + Uuid.fromLongs(array[0], array[1]) } } } diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Encoding.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Encoding.kt deleted file mode 100644 index f57e04d..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Encoding.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -internal const val UUID_BYTE_ARRAY_SIZE: Int = 16 - -/** - * Encode [UUID] as a byte array in its classic format, just like in text format, but as bytes. - */ -public fun UUID.encodeToByteArray(): ByteArray { - val result = ByteArray(UUID_BYTE_ARRAY_SIZE) - timeStampAndVersionRaw.copyInto(result, 0) - clockSequenceVariantAndNodeRaw.copyInto(result, 8) - return result -} - -/** - * Encodes [UUID] as a pair of long: there first long contains timestamp and version bits, - * the second one consists of clock sequence, variant and node. - */ -public fun UUID.encodeToLongArray(): LongArray { - return longArrayOf(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw) -} - -/** - * Creates [UUID] from bytes representation. - */ -public fun UUID(bytes: ByteArray): UUID { - require(bytes.size == UUID_BYTE_ARRAY_SIZE) { - "Input ByteArray should have size $UUID_BYTE_ARRAY_SIZE, but got array of ${bytes.size} bytes." - } - - return UUID.create( - bytes.getLongAt(0), - bytes.getLongAt(8) - ) -} - -/** - * Creates an instance of [UUID] from [longPair] where the first long value - * is timestamp and version bits and the second one consists of clock sequence, - * variant and node. - */ -public fun UUID(longPair: LongArray): UUID { - require(longPair.size == 2) { "Input LongArray should have size 2, but got array of ${longPair.size} values." } - return UUID.create( - longPair[0], - longPair[1] - ) -} - -private fun Long.copyInto(buffer: ByteArray, destinationOffset: Int) { - repeat(8) { index -> - buffer[destinationOffset + index] = (this ushr (56 - index * 8)).toByte() - } -} - -private fun ByteArray.getLongAt(offset: Int): Long { - var result = 0L - - repeat(8) { index -> - result = result or (this[offset + index].toLong() and 0xff shl ((7 - index) * 8)) - } - - return result -} diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Formatter.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Formatter.kt deleted file mode 100644 index fe83f87..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Formatter.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -/** - * Renders UUID in the RFC format: five groups of hexademical parts separated with - * minus characters and surrounded with curly brackets if [includeBrackets] is `true`, - * without spaces. - * `{1b3e4567-e99b-13d3-a476-446657420000}` - */ -internal fun formatUUID( - timeStampAndVersionRaw: Long, - clockSequenceVariantAndNodeRaw: Long, - includeBrackets: Boolean -): String = buildString(38) { - if (includeBrackets) { - append('{') - } - dumpHex(timeStampAndVersionRaw ushr 32, 4, this) - append('-') - dumpHex(timeStampAndVersionRaw ushr 16 and 0xffff, 2, this) - append('-') - dumpHex(timeStampAndVersionRaw and 0xffff, 2, this) - append('-') - dumpHex(clockSequenceVariantAndNodeRaw shr 48 and 0xffff, 2, this) - append('-') - dumpHex(clockSequenceVariantAndNodeRaw and 0xffffffffffffL, 6, this) - if (includeBrackets) { - append('}') - } -} - -internal fun dumpHex(value: Long, numberOfOctets: Int, out: StringBuilder) { - repeat(numberOfOctets) { index -> - val octet = value ushr ((numberOfOctets - index - 1) * 8) - dumpHalfByte(octet.toInt() shr 4, out) - dumpHalfByte(octet.toInt(), out) - } -} - -private fun dumpHalfByte(value: Int, out: StringBuilder) { - val half = value and 0x0f - out.append( - when { - half <= 9 -> '0' + half - else -> 'a' + half - 10 - } - ) -} diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Migration.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Migration.kt deleted file mode 100644 index 685548a..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Migration.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -import kotlin.random.* - -@Deprecated( - "Use version or versionNumber instead", - ReplaceWith("versionNumber") -) -public fun UUID.version(): Int = versionNumber - -@Deprecated("Use variant property instead", ReplaceWith("variant")) -public fun UUID.variant(): Int = variant - -@Deprecated("Use timeStamp property instead", ReplaceWith("timeStamp")) -public fun UUID.timestamp(): Long = timeStamp - -@Deprecated("Use clockSequence property instead", ReplaceWith("clockSequence")) -public fun UUID.clockSequence(): Int = clockSequence - -@Deprecated("Use node property instead", ReplaceWith("node")) -public fun UUID.node(): Long = node - -@Deprecated("Use UUID constructor instead", ReplaceWith("UUID(name)")) -public fun UUID.Companion.fromString(name: String): UUID = UUID(name) - -@Deprecated( - "Use UUID.generateUUID instead specifying Random if necessary (the default is non-secure!)", - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith("generateUUID(Random.Default)", "kotlin.random.Random"), -) -public fun UUID.Companion.randomUUID(): UUID { - return generateUUID(Random.Default) -} - -@Deprecated( - "Use UUID.generateUUID instead that does SHA-1 instead of MD5. " + - "So for the same input bytes it will produce other UUID than java.util.UUID.", - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith("UUID.generateUUID(bytes)") -) -@Suppress("unused_parameter") -public fun UUID.Companion.nameUUIDFromBytes(bytes: ByteArray): UUID { - return UUID.generateUUID(bytes) -} - -@Suppress("DeprecatedCallableAddReplaceWith") -@Deprecated( - "This is internal details that shouldn't be used. " + - "Please suppress and file a ticket if it is actually required.", - level = DeprecationLevel.ERROR -) -public fun UUID.getLeastSignificantBits(): Long = clockSequenceVariantAndNodeRaw - -@Suppress("DeprecatedCallableAddReplaceWith") -@Deprecated( - "This is internal details that shouldn't be used. " + - "Please suppress and file a ticket if it is actually required.", - level = DeprecationLevel.ERROR -) -public fun UUID.getMostSignificantBits(): Long = timeStampAndVersionRaw diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/NameBasedGenerator.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/NameBasedGenerator.kt index 05422cb..5a80b14 100644 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/NameBasedGenerator.kt +++ b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/NameBasedGenerator.kt @@ -6,25 +6,26 @@ package kotlinx.uuid import kotlinx.uuid.internal.* import kotlin.experimental.* +import kotlin.uuid.Uuid /** - * Generates a [UUID] instance by [namespace] and [name] applying SHA-1. + * Generates a [Uuid] instance by [namespace] and [name] applying SHA-1. * It doesn't use any random source, so it will produce the same result for * the same input values. * * See [RFC4122 sec 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) */ -public fun UUID.Companion.generateUUID(namespace: UUID, name: String): UUID { +public fun Uuid.Companion.generateUUID(namespace: Uuid, name: String): Uuid { val hash = sha1 { - update(namespace.encodeToByteArray()) + update(namespace.toByteArray()) update(name.encodeToByteArray()) } - return generateUUIDByHash(hash, version = UUID.Version.NAME_BASED_SHA1.id) + return generateUUIDByHash(hash, version = 5) } /** - * Generates a [UUID] instance by input [bytes] applying SHA-1. + * Generates a [Uuid] instance by input [bytes] applying SHA-1. * It doesn't use any random source, so it will produce the same result for * the same input values. * @@ -33,12 +34,12 @@ public fun UUID.Companion.generateUUID(namespace: UUID, name: String): UUID { * It is recommended to use generateUUID(namespace, name) instead while this function * is more for java.util.UUID parity. */ -public fun UUID.Companion.generateUUID(bytes: ByteArray): UUID { +public fun Uuid.Companion.generateUUID(bytes: ByteArray): Uuid { val hash = sha1 { update(bytes) } - return generateUUIDByHash(hash, version = UUID.Version.NAME_BASED_SHA1.id) + return generateUUIDByHash(hash, version = 5) } private inline fun sha1(builder: SHA1.() -> Unit): ByteArray { @@ -47,9 +48,9 @@ private inline fun sha1(builder: SHA1.() -> Unit): ByteArray { return sha1.final() } -private fun generateUUIDByHash(hashBytes: ByteArray, version: Int): UUID { +private fun generateUUIDByHash(hashBytes: ByteArray, version: Int): Uuid { hashBytes[6] = (hashBytes[6] and 0x0f or (version shl 4).toByte()) hashBytes[8] = hashBytes[8] and 0x3f or 0x80.toByte() - return UUID(hashBytes.copyOf(UUID_BYTE_ARRAY_SIZE)) + return Uuid.fromByteArray(hashBytes.copyOf(Uuid.SIZE_BYTES)) } diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Parser.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Parser.kt deleted file mode 100644 index 8f7519c..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Parser.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -internal fun parseUUID(text: String): UUID { - var textIndex = skipCharacters(text, 0, '{') - - // time low - var timeStampAndVersionRaw = parseOctetStride(text, textIndex, 4, 32) - textIndex = skipCharacters(text, textIndex + 8, '-') - - // time mid - timeStampAndVersionRaw = timeStampAndVersionRaw or - parseOctetStride(text, textIndex, 2, 16) - textIndex = skipCharacters(text, textIndex + 4, '-') - - // time high and version - timeStampAndVersionRaw = timeStampAndVersionRaw or - parseOctetStride(text, textIndex, 2, 0) - textIndex = skipCharacters(text, textIndex + 4, '-') - - // variant + clock - var clockSequenceVariantAndNodeRaw = parseOctetStride(text, textIndex, 2, 48) - textIndex = skipCharacters(text, textIndex + 4, '-') - - // node - clockSequenceVariantAndNodeRaw = clockSequenceVariantAndNodeRaw or - parseOctetStride(text, textIndex, 6, 0) - - textIndex = skipCharacters(text, textIndex + 12, '}') - - if (textIndex < text.length) { - error("extra trailing characters ${text.substring(textIndex)}", text, textIndex) - } - - return UUID.create(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw) -} - -private fun parseOctetStride( - text: String, - textIndex: Int, - numberOfOctets: Int, - shift: Int -): Long { - if (text.length - textIndex < numberOfOctets * 2) { - errorTooShort(text) - } - - var result = 0L - repeat(numberOfOctets * 2) { i -> - val halfByte = when (val character = text[textIndex + i]) { - in '0'..'9' -> character - '0' - in 'a'..'f' -> character - 'a' + 10 - in 'A'..'F' -> character - 'A' + 10 - else -> error("Unexpected octet character $character", text, textIndex + i) - } - result = result shl 4 or halfByte.toLong() - } - - return result shl shift -} - -private fun errorTooShort(text: String) { - error("UUID string is too short", text, -1) -} - -private fun skipCharacters(text: String, startIndex: Int, a: Char): Int { - for (index in startIndex until text.length) { - val character = text[index] - if (character == a || character == ' ' || character == '\t') { - continue - } - return index - } - return text.length -} - -private fun error(message: String, text: String, index: Int): Nothing { - throw UUIDFormatException( - when (index) { - -1 -> "Failed to parse UUID $text: $message" - else -> "Failed to parse UUID $text at position $index: $message" - } - ) -} diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/RandomGenerator.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/RandomGenerator.kt index 942faa4..027490c 100644 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/RandomGenerator.kt +++ b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/RandomGenerator.kt @@ -5,24 +5,30 @@ package kotlinx.uuid import kotlin.random.* +import kotlin.uuid.Uuid /** * Generates a random UUID v4 using the specified [random] source. - * It uses by default a [SecureRandom] instance. */ -public fun UUID.Companion.generateUUID(random: Random = SecureRandom): UUID { - // set version 4 (random) - val timeStampAndVersionRaw = random.nextLong() and -0xf001L or 0x4000L - - // set variant to 4 or 5 - // we keep the lower variant bit random as it is defined as "don't care" - val clockSequenceVariantAndNodeRaw: Long = random.nextLong() and - 0x3fffffffffffffffL or (0x80L shl 0x38) +public fun Uuid.Companion.random(random: Random): Uuid { + val randomBytes = random.nextBytes(16) + return uuidFromRandomBytes(randomBytes) +} - return create(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw) +// Copied from stdlib +private fun uuidFromRandomBytes(randomBytes: ByteArray): Uuid { + // clear version + randomBytes[6] = (randomBytes[6].toInt() and 0x0f).toByte() + // set to version 4 + randomBytes[6] = (randomBytes[6].toInt() or 0x40).toByte() + // clear variant + randomBytes[8] = (randomBytes[8].toInt() and 0x3f).toByte() + // set to IETF variant + randomBytes[8] = (randomBytes[8].toInt() or 0x80).toByte() + return Uuid.fromByteArray(randomBytes) } /** * Generates a random UUID v4 using this [Random] instance. */ -public fun Random.nextUUID(): UUID = UUID.generateUUID(this) +public fun Random.nextUuid(): Uuid = Uuid.random(this) diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/SecureRandom.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/SecureRandom.kt deleted file mode 100644 index aaa9204..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/SecureRandom.kt +++ /dev/null @@ -1,13 +0,0 @@ -package kotlinx.uuid - -import kotlin.random.* - -/** - * Returns a platform dependent SecureRandom instance. - * - On JVM, it uses `java.util.SecureRandom` - * - On JS, it uses `window.crypto` or `nodejs.crypto`. - * - On darwin, it uses `SecRandomCopyBytes`. - * - On mingw, it uses `BCryptRandom`. - * - On Linux and Android native, it uses `DevUrandom`. - */ -public expect val SecureRandom: Random diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Serializer.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Serializer.kt deleted file mode 100644 index f7437e6..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/Serializer.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** - * This is the default [UUID] serializer that encodes instances as primitive strings - * consisting of the canonical UUID string format. - * - * @property includeBrackets specifies, if serialized UUID should be wrapped into curly brackets - */ -public sealed class Serializer( - private val includeBrackets: Boolean -) : KSerializer { - final override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING) - - final override fun deserialize(decoder: Decoder): UUID { - return UUID(decoder.decodeString()) - } - - final override fun serialize(encoder: Encoder, value: UUID) { - encoder.encodeString(value.toString(includeBrackets)) - } - - /** - * The default serializer instance that encodes without curly brackets. - */ - public object Default : Serializer(false) - - /** - * This serializer encodes [UUID] with curly brackets - */ - public object WrappedCurlyBrackets : Serializer(true) -} diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID.kt index e6e1652..26a9768 100644 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID.kt +++ b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID.kt @@ -4,222 +4,104 @@ package kotlinx.uuid -import kotlinx.serialization.* -import kotlinx.uuid.internal.* -import kotlin.jvm.* +import kotlin.uuid.Uuid /** - * This type represents a UUID as per RFC - * See: https://tools.ietf.org/html/rfc4122 + * Creates an instance of [Uuid] from components */ -@CommonParcelize -@Serializable(with = Serializer.Default::class) -public class UUID internal constructor( - internal val timeStampAndVersionRaw: Long, - internal val clockSequenceVariantAndNodeRaw: Long, -) : CommonParcelable, Comparable { - private constructor( - helper: UUID - ) : this( - helper.timeStampAndVersionRaw, - helper.clockSequenceVariantAndNodeRaw - ) - - /** - * Creates an instance by the string [uuid] representation. - * An input string should consist of five hexadecimal parts - * separated with the minus character, and optionally surrounded with curly brackets. - * The space and tab characters are ignored at the end and at the beginning - * and surrounding brackets and minus characters. - * - * Valid examples: - * `1b3e4567-e99b-13d3-a476-446657420000`, - * ` 1b3e4567-e99b-13d3 - a476 - 446657420000 `, - * `{123e4567-e89b-12d3-a456-426655440000}`, - * `{ 123e4567-e89b-12d3-a456-426655440000}` - */ - public constructor(uuid: String) : this(parseUUID(uuid)) - - /** - * Creates a new Version 4 Random based instance using a [SecureRandom] generator. - */ - public constructor() : this(SecureRandom.nextUUID()) - - /** - * Creates an instance of [UUID] from components - */ - public constructor( - versionNumber: Int, - timeStamp: Long, - clockSequence: Int, - node: Long, - variant: Int = 5 - ) : this( - timeStampAndVersionRaw = (timeStamp shl 32) or (timeStamp and 0xffff00000000L shr 16) or - (timeStamp shr 48) or (versionNumber.toLong() shl 12), - clockSequenceVariantAndNodeRaw = (clockSequence.toLong() shl 48) or - (variant.toLong() shl 61) or node - ) { - require(versionNumber in 0..15) - require(variant in 0..7) - require(timeStamp in 0L until (1L shl 60)) - require(node in 0L until (1L shl 48)) - require(clockSequence in 0 until (1 shl 13)) - } - - /** - * Creates an instance of [UUID] from components - */ - public constructor( - version: Version, - timeStamp: Long, - clockSequence: Int, - node: Long, - variant: Int = 5 - ) : this(version.id, timeStamp, clockSequence, node, variant) +public fun Uuid.Companion.from( + versionNumber: Int, + timeStamp: Long, + clockSequence: Int, + node: Long, + variant: Int = 5 +): Uuid { + require(versionNumber in 0..15) + require(variant in 0..7) + require(timeStamp in 0L until (1L shl 60)) + require(node in 0L until (1L shl 48)) + require(clockSequence in 0 until (1 shl 13)) + + val timeStampAndVersionRaw = (timeStamp shl 32) or (timeStamp and 0xffff00000000L shr 16) or + (timeStamp shr 48) or (versionNumber.toLong() shl 12) + val clockSequenceVariantAndNodeRaw = (clockSequence.toLong() shl 48) or + (variant.toLong() shl 61) or node + + return fromLongs(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw) +} - /** - * A 60-bits non-negative number. Depending on the UUID version it could have different semantics: - * - UTC time - * - a number constructed from the namespace - * - a random number - */ - public val timeStamp: Long - get() = (timeStampAndVersionRaw ushr 32) or +/** + * A 60-bits non-negative number. Depending on the UUID version it could have different semantics: + * - UTC time + * - a number constructed from the namespace + * - a random number + */ +public val Uuid.timeStamp: Long + get() = toLongs { timeStampAndVersionRaw, _ -> + (timeStampAndVersionRaw ushr 32) or (timeStampAndVersionRaw and 0xffff0000L shl 16) or (timeStampAndVersionRaw and 0x0fffL shl 48) - - /** - * 13-bits non-negative number representing a sequence number - * or a random number depending on UUID [version] and [variant]. - */ - public val clockSequence: Int - get() = (clockSequenceVariantAndNodeRaw shr 48 and 0x1fff).toInt() - - /** - * UUID numeric version in range `[0..15] - * @see version - */ - public val versionNumber: Int - get() = (timeStampAndVersionRaw and 0xf000L shr 12).toInt() - - /** - * UUID RFC version or `null` if unknown version number or another variant - * @see versionNumber - */ - public val version: Version? - get() = when { - isRfcVariant -> versionFor(versionNumber) - else -> null - } - - /** - * UUID variant in range `[0..7]`, similar to version - */ - public val variant: Int - get() = (clockSequenceVariantAndNodeRaw ushr 61).toInt() - - /** - * UUID variant specified and documented by the RFC - */ - public val isRfcVariant: Boolean - get() = variant in 4..5 - - /** - * Node UUID part, a 48-bit non-negative number. - * Depending on [version] and [variant] it could be one of the following: - * - a MAC address - * - a random number - * - a value constructed from a namespace - */ - public val node: Long - get() = clockSequenceVariantAndNodeRaw and 0xffffffffffffL - - /** - * Renders UUID in the RFC format: five groups of hexademical parts separated with - * minus characters, without spaces and without curly brackets. - * `1b3e4567-e99b-13d3-a476-446657420000` - */ - override fun toString(): String = toString(false) - - /** - * Renders UUID in the RFC format: five groups of hexademical parts separated with - * minus characters and surrounded with curly brackets if [includeBrackets] is `true`, - * without spaces. - * `{1b3e4567-e99b-13d3-a476-446657420000}` - */ - public fun toString(includeBrackets: Boolean): String = - formatUUID(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw, includeBrackets) - - override fun hashCode(): Int { - return timeStampAndVersionRaw.hashCode() + clockSequenceVariantAndNodeRaw.hashCode() } - override fun equals(other: Any?): Boolean { - return other is UUID && - other.clockSequenceVariantAndNodeRaw == clockSequenceVariantAndNodeRaw && - other.timeStampAndVersionRaw == timeStampAndVersionRaw - } - - override fun compareTo(other: UUID): Int { - timeStampAndVersionRaw.compareTo(other.timeStampAndVersionRaw).let { - if (it != 0) return it - } +/** + * 13-bits non-negative number representing a sequence number + * or a random number depending on UUID [version] and [variant]. + */ +public val Uuid.clockSequence: Int + get() = toLongs { _, clockSequenceVariantAndNodeRaw -> (clockSequenceVariantAndNodeRaw shr 48 and 0x1fff).toInt() } - return clockSequenceVariantAndNodeRaw.compareTo(other.clockSequenceVariantAndNodeRaw) +/** + * UUID [numeric version](https://tools.ietf.org/html/rfc4122#section-4.1.3) in range `[0..15] + */ +public val Uuid.versionNumber: Int + get() = toLongs { timeStampAndVersionRaw, _ -> + (timeStampAndVersionRaw and 0xf000L shr 12).toInt() } - /** - * UUID versions - * https://tools.ietf.org/html/rfc4122#section-4.1.3 - */ - public enum class Version(internal val id: Int) { - TIME_BASED(1), - DCE_SECURITY(2), - NAME_BASED_MD5(3), - RANDOM_BASED(4), - NAME_BASED_SHA1(5) +/** + * UUID variant in range `[0..7]`, similar to version + */ +public val Uuid.variant: Int + get() = toLongs { _, clockSequenceVariantAndNodeRaw -> + (clockSequenceVariantAndNodeRaw ushr 61).toInt() } - public companion object { - /** - * A Nil UUID with all fields set to zero. - * https://tools.ietf.org/html/rfc4122#section-4.1.7 - */ - public val NIL: UUID = create(0L, 0L) - - /** - * Check the [spec] string to conform to UUID - * @return `true` if the [spec] string is a UUID string - */ - public fun isValidUUIDString(spec: String): Boolean = try { - parseUUID(spec) - true - } catch (_: UUIDFormatException) { - false - } +/** + * UUID variant specified and documented by the RFC + */ +public val Uuid.isRfcVariant: Boolean get() = variant == 4 || variant == 5 - internal fun create( - timeStampAndVersionRaw: Long, - clockSequenceVariantAndNodeRaw: Long - ): UUID { - return UUID(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw) - } +/** + * Node UUID part, a 48-bit non-negative number. + * Depending on [version] and [variant] it could be one of the following: + * - a MAC address + * - a random number + * - a value constructed from a namespace + */ +public val Uuid.node: Long + get() = toLongs { _, clockSequenceVariantAndNodeRaw -> clockSequenceVariantAndNodeRaw and 0xffffffffffffL } - private fun versionFor(id: Int): Version? = Version.entries.firstOrNull { it.id == id } - } +/** + * Check the [spec] string to conform to UUID + * @return `true` if the [spec] string is a UUID string + */ +public fun Uuid.Companion.isValidUUIDString(spec: String): Boolean = try { + parse(spec) + true +} catch (_: IllegalArgumentException) { + false } /** - * Convert this String to a [UUID], or throws a [UUIDFormatException] if [this] is a malformed UUID. + * Convert this String to a [Uuid], or throws a [IllegalArgumentException] if [this] is a malformed UUID. */ -public fun String.toUUID(): UUID = parseUUID(this) +public fun String.toUuid(): Uuid = Uuid.parse(this) /** - * Convert this String to a [UUID], or returns null if [this] is a malformed UUID. + * Convert this String to a [Uuid], or returns null if [this] is a malformed UUID. */ -public fun String.toUUIDOrNull(): UUID? = try { - parseUUID(this) -} catch (_: UUIDFormatException) { +public fun String.toUUIDOrNull(): Uuid? = try { + Uuid.parse(this) +} catch (_: IllegalArgumentException) { null } diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt index 09f27e1..d83a4bd 100644 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt +++ b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt @@ -1,7 +1,7 @@ package kotlinx.uuid -import kotlinx.uuid.UUID.Companion.create import kotlin.random.Random +import kotlin.uuid.Uuid private const val UNIX_48_TIMESTAMP = 0x1FFF_FFFF_FFFF_FL @@ -11,25 +11,32 @@ private const val UNIX_48_TIMESTAMP = 0x1FFF_FFFF_FFFF_FL * * [timeStamp] must be an 48 bit unix timestamp. */ -@UUIDExperimentalAPI -public fun UUIDv7(timeStamp: Long, random: Random = SecureRandom): UUID { +public fun UUIDv7(timeStamp: Long, random: Random): Uuid { require(timeStamp <= UNIX_48_TIMESTAMP) { "timeStamp $timeStamp must be <= 48 bits, was $timeStamp." } - val helper = random.nextUUID() + val ( + helperTimeStampAndVersionRaw, + helperClockSequenceVariantAndNodeRaw + ) = random.nextUuid().toLongs { mostSignificantBits, leastSignificantBits -> + mostSignificantBits to leastSignificantBits + } val leftTimeStamp = timeStamp shl 16 // set version to 0b0111 val leftTimeStampAndVersion = leftTimeStamp or 28672 - val rand_a = helper.timeStamp and 4095 - val timeStampAndVersionRaw = leftTimeStampAndVersion or rand_a + val randA = helperTimeStampAndVersionRaw.let { timeStampAndVersionRaw -> + (timeStampAndVersionRaw ushr 32) or + (timeStampAndVersionRaw and 0xffff0000L shl 16) or + (timeStampAndVersionRaw and 0x0fffL shl 48) + } and 4095 + val timeStampAndVersionRaw = leftTimeStampAndVersion or randA // set variant to 0b10 - val clockSequenceVariantAndNodeRaw = (2L shl 62) or (helper.clockSequenceVariantAndNodeRaw ushr 2) + val clockSequenceVariantAndNodeRaw = (2L shl 62) or (helperClockSequenceVariantAndNodeRaw ushr 2) - return create(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw) + return Uuid.fromLongs(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw) } /** * The UUIDv7 48 bit big-endian unsigned number of Unix epoch timestamp in milliseconds */ -@UUIDExperimentalAPI -public val UUID.unixTimeStamp: Long get() = timeStampAndVersionRaw ushr 16 +public val Uuid.unixTimeStamp: Long get() = toLongs { mostSignificantBits, _ -> mostSignificantBits ushr 16 } diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUIDExperimental.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUIDExperimental.kt deleted file mode 100644 index 055adae..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUIDExperimental.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -/** - * The API marked with this annotation is experimental. Its stability is not guaranteed, and you shouldn't rely on it. - * - * @property plannedVersion in which this API is planned to be stabilized - */ -@RequiresOptIn( - "This UUID API is experimental and could be changed in future releases.", - level = RequiresOptIn.Level.WARNING -) -@Retention(AnnotationRetention.BINARY) -@Target( - AnnotationTarget.CLASS, - AnnotationTarget.TYPEALIAS, - AnnotationTarget.FUNCTION, - AnnotationTarget.PROPERTY -) -public annotation class UUIDExperimentalAPI(val plannedVersion: String = "") - -/** - * The API marked with this annotation is internal and should be never used - * outside this library. It's stability, behaviour and compatibility is not guaranteed - * and could be changed in any release without notice. - */ -@RequiresOptIn( - "This API is internal", - level = RequiresOptIn.Level.ERROR -) -@Retention(AnnotationRetention.BINARY) -@Target( - AnnotationTarget.CLASS, - AnnotationTarget.TYPEALIAS, - AnnotationTarget.FUNCTION, - AnnotationTarget.PROPERTY -) -public annotation class InternalAPI diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUIDFormatException.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUIDFormatException.kt deleted file mode 100644 index c9a2c48..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUIDFormatException.kt +++ /dev/null @@ -1,3 +0,0 @@ -package kotlinx.uuid - -internal class UUIDFormatException(override val message: String) : IllegalArgumentException(message) diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/internal/Parcelable.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/internal/Parcelable.kt deleted file mode 100644 index 15c6dd3..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/internal/Parcelable.kt +++ /dev/null @@ -1,6 +0,0 @@ -package kotlinx.uuid.internal - -@Target(AnnotationTarget.CLASS) -internal annotation class CommonParcelize - -public expect interface CommonParcelable diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/internal/ToInt.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/internal/ToInt.kt deleted file mode 100644 index 64ee375..0000000 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/internal/ToInt.kt +++ /dev/null @@ -1,9 +0,0 @@ -package kotlinx.uuid.internal - -internal fun ByteArray.toInt(): Int { - var result = 0 - for (byte in this) { - result = (result or byte.toInt()) shl Byte.SIZE_BITS - } - return result -} diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/BinarySerializationTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/BinarySerializationTest.kt index aeba5d2..2d38b76 100644 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/BinarySerializationTest.kt +++ b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/BinarySerializationTest.kt @@ -11,21 +11,13 @@ import kotlinx.serialization.encoding.* import kotlinx.serialization.json.* import kotlinx.serialization.modules.* import kotlin.test.* +import kotlin.uuid.Uuid -@OptIn(ExperimentalSerializationApi::class) +@ExperimentalSerializationApi class BinarySerializationTest { - @Test - fun smokeTestWithDefaultSerializer() { - val value = UUID(SOME_UUID_STRING) - val encoded = Cbor.encodeToHexString(value) - val decoded = Cbor.decodeFromHexString(encoded) - - assertEquals(value, decoded) - } - @Test fun smokeTest() { - val value = UUID(SOME_UUID_STRING) + val value = Uuid.parse(SOME_UUID_STRING) val encoded = Cbor.encodeToHexString(BinarySerializer, value) val decoded = Cbor.decodeFromHexString(BinarySerializer, encoded) @@ -50,7 +42,7 @@ class BinarySerializationTest { @Test fun testWithJson() { - val initial = UUID(SOME_UUID_STRING) + val initial = Uuid.parse(SOME_UUID_STRING) val encoded = Json.encodeToString(BinarySerializer, initial) val decoded = Json.decodeFromString(BinarySerializer, encoded) assertEquals(initial, decoded) diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/DumpHexTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/DumpHexTest.kt deleted file mode 100644 index c6ae085..0000000 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/DumpHexTest.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -import kotlin.test.* - -class DumpHexTest { - @Test - fun smoke() { - assertEquals("ff", dumpHex(0xff, 1)) - assertEquals("00ff", dumpHex(0xff, 2)) - assertEquals("0000ff", dumpHex(0xff, 3)) - - assertEquals("12345678", dumpHex(0x12345678, 4)) - assertEquals("9abcdef0", dumpHex(0x9abcdef0, 4)) - - assertEquals("ffffffff", dumpHex(-1, 4)) - } - - @Test - fun testZeroes() { - assertEquals("0f", dumpHex(0x0f, 1)) - assertEquals("f0", dumpHex(0xf0, 1)) - assertEquals("00", dumpHex(0, 1)) - assertEquals("0f00", dumpHex(0x0f00, 2)) - assertEquals("f000", dumpHex(0xf000, 2)) - - assertEquals("0a", dumpHex(0x0a, 1)) - assertEquals("09", dumpHex(0x09, 1)) - } - - @Test - fun testCut() { - assertEquals("34", dumpHex(0x1234, 1)) - } - - private fun dumpHex(value: Long, numberOfOctets: Int): String = buildString { - dumpHex(value, numberOfOctets, this) - } -} diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/EncodingTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/EncodingTest.kt deleted file mode 100644 index 55687ad..0000000 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/EncodingTest.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -import kotlin.test.* - -class EncodingTest { - @Test - fun testEncodeToByteArray() { - val bytes = UUID(SOME_UUID_STRING).encodeToByteArray() - assertEquals( - SOME_UUID_STRING.explodeToBytes(), - bytes.asList() - ) - } - - @Test - fun testEncodeToLongArray() { - val uuid = UUID(SOME_UUID_STRING) - val longValues = uuid.encodeToLongArray() - assertEquals(uuid.timeStampAndVersionRaw, longValues[0]) - assertEquals(uuid.clockSequenceVariantAndNodeRaw, longValues[1]) - } - - @Test - fun testCreateFromByteArray() { - val uuid = UUID(SOME_UUID_STRING.explodeToBytes().toByteArray()) - assertEquals(UUID(SOME_UUID_STRING), uuid) - } - - @Test - fun testCreateFromWrongByteArray() { - assertFailsWith { - UUID(ByteArray(1)) - } - } - - @Test - fun testCreateFromLongArray() { - val original = UUID(SOME_UUID_STRING) - val array = original.let { - longArrayOf(it.timeStampAndVersionRaw, it.clockSequenceVariantAndNodeRaw) - } - - val uuid = UUID(array) - assertEquals(original, uuid) - } - - @Test - fun testCreateFromWrongLongArray() { - assertFailsWith { - UUID(LongArray(1)) - } - } -} - -internal fun String.explodeToBytes(): List { - return replace("-", "") - .windowed(2, 2) { - it.toString().toInt(radix = 16).toByte() - } -} diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/GenerationTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/GenerationTest.kt index 90798bd..5f53d2e 100644 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/GenerationTest.kt +++ b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/GenerationTest.kt @@ -6,53 +6,51 @@ package kotlinx.uuid import kotlin.random.* import kotlin.test.* +import kotlin.uuid.Uuid class GenerationTest { @Test fun smokeTest() { - UUID.generateUUID().assertRandomGenerated() + Uuid.random().assertRandomGenerated() } @Test fun customRandomImpl() { - UUID.generateUUID(Random(777)).assertRandomGenerated() - UUID.generateUUID(Random(778)).assertRandomGenerated() - assertEquals(UUID.generateUUID(Random(777)), UUID.generateUUID(Random(777))) - assertNotEquals(UUID.generateUUID(Random(777)), UUID.generateUUID(Random(778))) + Uuid.random(Random(777)).assertRandomGenerated() + Uuid.random(Random(778)).assertRandomGenerated() + assertEquals(Uuid.random(Random(777)), Uuid.random(Random(777))) + assertNotEquals(Uuid.random(Random(777)), Uuid.random(Random(778))) } @Test fun testRandomExtension() { - Random.nextUUID().assertRandomGenerated() + Random.nextUuid().assertRandomGenerated() } @Test fun testGenerateFromName() { - val baseUUID = UUID(SOME_UUID_STRING) - val generated = UUID.generateUUID(baseUUID, "test") + val baseUUID = Uuid.parse(SOME_UUID_STRING) + val generated = Uuid.generateUUID(baseUUID, "test") assertEquals(5, generated.versionNumber) - assertEquals(UUID.Version.NAME_BASED_SHA1, generated.version) assertEquals("9dc3df60-4ed1-5ea9-9e66-5c2030d5827b", generated.toString()) } @Test fun testGenerateFromBytes() { - val generated = UUID.generateUUID(SOME_UUID_STRING.explodeToBytes().toByteArray()) + val generated = Uuid.generateUUID(SOME_UUID_STRING.explodeToBytes().toByteArray()) assertEquals(5, generated.versionNumber) - assertEquals(UUID.Version.NAME_BASED_SHA1, generated.version) assertEquals("29e5befd-ca93-58bf-9ef0-30f7da112935", generated.toString()) } - @Test - fun testGenerateFromBytesMigration() { - @Suppress("DEPRECATION_ERROR") - val generated = UUID.nameUUIDFromBytes(SOME_UUID_STRING.explodeToBytes().toByteArray()) - assertEquals(5, generated.versionNumber) - assertEquals(UUID.Version.NAME_BASED_SHA1, generated.version) - } - - private fun UUID.assertRandomGenerated() { + private fun Uuid.assertRandomGenerated() { assertTrue(isRfcVariant) assertEquals(4, versionNumber) } + + private fun String.explodeToBytes(): List { + return replace("-", "") + .windowed(2, 2) { + it.toString().toInt(radix = 16).toByte() + } + } } diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/ParserTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/ParserTest.kt deleted file mode 100644 index a39bdf9..0000000 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/ParserTest.kt +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -import kotlin.test.* - -internal const val SOME_UUID_STRING: String = "1b3e4567-e99b-13d3-a476-446657420000" - -class ParserTest { - @Test - fun smoke() { - parseUUID(SOME_UUID_STRING).assertFields() - parseUUID(SOME_UUID_STRING.replace('b', 'B')).assertFields() - parseUUID(SOME_UUID_STRING.uppercase()).assertFields() - parseUUID(SOME_UUID_STRING.uppercase().replace('B', 'b')).assertFields() - } - - @Test - fun testUnexpectedCharacter() { - assertFailsWith { - parseUUID(SOME_UUID_STRING.replace('b', 'X')) - }.let { - assertTrue(it.message.contains("Unexpected octet character")) - assertTrue(it.message.contains("X")) - } - - assertFailsWith { - parseUUID(SOME_UUID_STRING.replace('b', '.')) - }.let { - assertTrue(it.message.contains("Unexpected octet character")) - assertTrue(it.message.contains(".")) - } - - assertFailsWith { - parseUUID(SOME_UUID_STRING.replace('b', 'x')) - }.let { - assertTrue(it.message.contains("Unexpected octet character")) - assertTrue(it.message.contains("x")) - } - - assertFailsWith { - parseUUID(SOME_UUID_STRING.uppercase().replace('B', 'X')) - }.let { - assertTrue(it.message.contains("Unexpected octet character")) - assertTrue(it.message.contains("X")) - } - - assertFailsWith { - parseUUID(SOME_UUID_STRING.uppercase().replace('B', 'x')) - }.let { - assertTrue(it.message.contains("Unexpected octet character")) - assertTrue(it.message.contains("x")) - } - - assertFailsWith { - parseUUID(SOME_UUID_STRING.uppercase().replace('B', '.')) - }.let { - assertTrue(it.message.contains("Unexpected octet character")) - assertTrue(it.message.contains(".")) - } - } - - @Test - fun curlyBrackets() { - parseUUID("{$SOME_UUID_STRING}").assertFields() - } - - @Test - fun spaces() { - for (space in listOf(" ", "\t")) { - parseUUID("$SOME_UUID_STRING$space").assertFields() - parseUUID("$space$SOME_UUID_STRING$space").assertFields() - parseUUID("$space$SOME_UUID_STRING").assertFields() - parseUUID(SOME_UUID_STRING.replace("-", "$space-$space")).assertFields() - parseUUID("$space{$SOME_UUID_STRING}$space").assertFields() - parseUUID("$space{$space$SOME_UUID_STRING$space}$space").assertFields() - } - } - - @Test - fun parseEmpty() { - assertFailsWith { - parseUUID("") - }.let { cause -> - assertEquals("UUID string is too short", cause.message.substringAfter(":").trim()) - } - } - - @Test - fun parseIncomplete() { - for (size in 1 until SOME_UUID_STRING.length) { - assertFailsWith { - parseUUID(SOME_UUID_STRING.substring(0, size)) - }.let { cause -> - assertEquals("UUID string is too short", cause.message.substringAfter(":").trim()) - } - } - } - - @Test - fun parseIllegalCharacter() { - for (replaceIndex in SOME_UUID_STRING.indices) { - assertFailsWith { - parseUUID(SOME_UUID_STRING.replaceAt(replaceIndex)) - }.let { cause -> - assertEquals("Unexpected octet character #", cause.message.substringAfter(":").trim()) - } - } - } - - @Test - fun trailing() { - assertFailsWith { - parseUUID("$SOME_UUID_STRING 000") - }.let { cause -> - assertEquals("extra trailing characters 000", cause.message.substringAfter(":").trim()) - } - } - - @Test - @Suppress("DEPRECATION") - fun migrationFromString() { - assertEquals(UUID(SOME_UUID_STRING), UUID.fromString(SOME_UUID_STRING)) - } - - private fun String.replaceAt(atIndex: Int): String = replaceAt(atIndex, '#') - - private fun String.replaceAt(atIndex: Int, newCharacter: Char): String = buildString(length) { - if (atIndex > 0) { - append(this@replaceAt, 0, atIndex) - } - append(newCharacter) - if (atIndex < this@replaceAt.lastIndex) { - append(this@replaceAt, atIndex + 1, this@replaceAt.length) - } - } - - private fun UUID.assertFields() { - assertEquals(1, versionNumber) - assertEquals(UUID.Version.TIME_BASED, version) - assertEquals(5, variant) - assertEquals("3d3e99b1b3e4567", timeStamp.toString(16)) - assertEquals("476", clockSequence.toString(16)) - assertEquals("446657420000", node.toString(16)) - - assertMigrations() - } - - @Suppress("DEPRECATION") - private fun UUID.assertMigrations() { - assertEquals(1, version()) - assertEquals(5, variant()) - assertEquals("3d3e99b1b3e4567", timestamp().toString(16)) - assertEquals("476", clockSequence().toString(16)) - assertEquals("446657420000", node().toString(16)) - } -} diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/SecureRandomTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/SecureRandomTest.kt deleted file mode 100644 index 127d7c0..0000000 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/SecureRandomTest.kt +++ /dev/null @@ -1,15 +0,0 @@ -package kotlinx.uuid - -import kotlin.test.* - -class SecureRandomTest { - @Test - fun random() { - repeat(10) { - val result = List(1000) { - SecureRandom.nextLong() - }.toSet() - assertTrue(result.size in 990..1000, message = "$it: ${result.size}") - } - } -} diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/SerializationTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/SerializationTest.kt deleted file mode 100644 index 0aaab18..0000000 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/SerializationTest.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.json.* -import kotlin.test.* - -@ExperimentalSerializationApi -class SerializationTest { - @Test - fun smokeTest() { - assertEquals("\"$SOME_UUID_STRING\"", Json.encodeToString(UUID(SOME_UUID_STRING))) - assertEquals(UUID(SOME_UUID_STRING), Json.decodeFromString("\"$SOME_UUID_STRING\"")) - assertTrue(UUID.serializer() is Serializer) - } - - @Test - fun serializeClass() { - assertEquals( - "{\"p\":\"$SOME_UUID_STRING\"}", - Json.encodeToString(E(UUID(SOME_UUID_STRING))) - ) - - assertEquals( - E(UUID(SOME_UUID_STRING)), - Json.decodeFromString("{ \"p\": \"$SOME_UUID_STRING\" }") - ) - } - - @Test - fun testCustomizeSerializer() { - assertEquals( - "\"{$SOME_UUID_STRING}\"", - Json.encodeToString(Serializer.WrappedCurlyBrackets, UUID(SOME_UUID_STRING)) - ) - assertEquals( - "\"$SOME_UUID_STRING\"", - Json.encodeToString(Serializer.Default, UUID(SOME_UUID_STRING)) - ) - assertEquals( - "\"$SOME_UUID_STRING\"", - Json.encodeToString(Serializer.Default, UUID(SOME_UUID_STRING)) - ) - } - - @Test - fun testDescriptor() { - val descriptor = Serializer.Default.descriptor - - assertEquals(PrimitiveKind.STRING, descriptor.kind) - assertEquals(false, descriptor.isNullable) - } - - @Serializable - class E(val p: UUID) { - override fun equals(other: Any?): Boolean = other is E && p == other.p - override fun hashCode(): Int = p.hashCode() - } -} diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/UUIDTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/UUIDTest.kt index 86e9940..50c4275 100644 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/UUIDTest.kt +++ b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/UUIDTest.kt @@ -4,76 +4,54 @@ package kotlinx.uuid +import kotlin.random.Random import kotlin.test.* +import kotlin.uuid.Uuid private const val UUID_STRING_ALL_FF: String = "ffffffff-ffff-ffff-ffff-ffffffffffff" private const val UUID_STRING: String = "1b3e4567-e99b-13d3-a476-446657420000" -private const val UUID_STRING2: String = "1b3e4567-e99b-13d3-a476-446657420001" -private const val UUID_STRING3: String = "1b3e4568-e99b-13d3-a476-446657420000" +internal const val SOME_UUID_STRING: String = "1b3e4567-e99b-13d3-a476-446657420000" class UUIDTest { @Test fun testZero() { - assertEquals(0, UUID.NIL.variant) - assertEquals(0, UUID.NIL.versionNumber) - assertNull(UUID.NIL.version) - assertEquals(0, UUID.NIL.timeStamp) - assertEquals(0, UUID.NIL.clockSequence) - assertEquals(0, UUID.NIL.node) - assertEquals(false, UUID.NIL.isRfcVariant) + assertEquals(0, Uuid.NIL.variant) + assertEquals(0, Uuid.NIL.versionNumber) + assertEquals(0, Uuid.NIL.timeStamp) + assertEquals(0, Uuid.NIL.clockSequence) + assertEquals(0, Uuid.NIL.node) + assertEquals(false, Uuid.NIL.isRfcVariant) } @Test fun testConstructingFromString() { - val uuid = UUID(UUID_STRING) + val uuid = Uuid.parse(UUID_STRING) assertEquals(1, uuid.versionNumber) - assertEquals(UUID.Version.TIME_BASED, uuid.version) assertEquals(5, uuid.variant) assertEquals("3d3e99b1b3e4567", uuid.timeStamp.toString(16)) assertEquals("476", uuid.clockSequence.toString(16)) assertEquals("446657420000", uuid.node.toString(16)) - assertEquals(uuid, UUID_STRING.toUUID()) + assertEquals(uuid, UUID_STRING.toUuid()) assertEquals(uuid, UUID_STRING.toUUIDOrNull()) } @Test fun testConstructingFromStringAllFf() { - val uuid = UUID(UUID_STRING_ALL_FF) + val uuid = Uuid.parse(UUID_STRING_ALL_FF) assertEquals(0xf, uuid.versionNumber) - assertEquals(null, uuid.version) assertEquals(7, uuid.variant) assertEquals("fffffffffffffff", uuid.timeStamp.toString(16)) assertEquals("1fff", uuid.clockSequence.toString(16)) assertEquals("ffffffffffff", uuid.node.toString(16)) } - @Test - fun testToString() { - val uuid = UUID(UUID_STRING) - assertEquals(UUID_STRING, uuid.toString()) - assertEquals("{1b3e4567-e99b-13d3-a476-446657420000}", uuid.toString(true)) - } - - @Test - fun testConstructingFromStringValid() { - val combined = setOf( - UUID("1b3e4567-e99b-13d3-a476-446657420000 "), - UUID("1b3e4567-e99b-13d3-a476 - 446657420000"), - UUID(" 1b3e4567-e99b-13d3-a476 - 446657420000"), - UUID(" { 1b3e4567-e99b-13d3-a476 - 446657420000}"), - UUID("{1b3e4567-e99b-13d3-a476 - 446657420000}") - ) - - assertEquals(1, combined.size) - } - @Test fun testConstructingFromComponents() { - val first = UUID(SOME_UUID_STRING) - val second = UUID( + val first = Uuid.parse(SOME_UUID_STRING) + val second = Uuid.from( timeStamp = first.timeStamp, versionNumber = first.versionNumber, clockSequence = first.clockSequence, @@ -84,23 +62,10 @@ class UUIDTest { assertEquals(first, second) } - @Test - fun testConstructingFromComponentsWithVersion() { - val first = UUID(SOME_UUID_STRING) - val second = UUID( - timeStamp = first.timeStamp, - version = first.version!!, - clockSequence = first.clockSequence, - node = first.node - ) - - assertEquals(first, second) - } - @Test fun testConstructingFromComponentsDefaultVariant() { - val first = UUID(SOME_UUID_STRING) - val second = UUID( + val first = Uuid.parse(SOME_UUID_STRING) + val second = Uuid.from( timeStamp = first.timeStamp, versionNumber = first.versionNumber, clockSequence = first.clockSequence, @@ -112,8 +77,8 @@ class UUIDTest { @Test fun testConstructingFromComponentsAllFf() { - val first = UUID(UUID_STRING_ALL_FF) - val second = UUID( + val first = Uuid.parse(UUID_STRING_ALL_FF) + val second = Uuid.from( timeStamp = first.timeStamp, versionNumber = first.versionNumber, clockSequence = first.clockSequence, @@ -124,128 +89,80 @@ class UUIDTest { assertEquals(first, second) assertFailsWith { - UUID(100, first.timeStamp, first.clockSequence, first.node, first.variant) + Uuid.from(100, first.timeStamp, first.clockSequence, first.node, first.variant) } assertFailsWith { - UUID(1, first.timeStamp, first.clockSequence, first.node, 100) + Uuid.from(1, first.timeStamp, first.clockSequence, first.node, 100) } assertFailsWith { - UUID(1, Long.MAX_VALUE, first.clockSequence, first.node, first.variant) + Uuid.from(1, Long.MAX_VALUE, first.clockSequence, first.node, first.variant) } assertFailsWith { - UUID(first.versionNumber, first.timeStamp, Int.MAX_VALUE, first.node, first.variant) + Uuid.from(first.versionNumber, first.timeStamp, Int.MAX_VALUE, first.node, first.variant) } assertFailsWith { - UUID(first.versionNumber, first.timeStamp, first.clockSequence, Long.MAX_VALUE, first.variant) + Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, Long.MAX_VALUE, first.variant) } assertFailsWith { - UUID(-1, first.timeStamp, first.clockSequence, first.node, first.variant) + Uuid.from(-1, first.timeStamp, first.clockSequence, first.node, first.variant) } assertFailsWith { - UUID(first.versionNumber, -1, first.clockSequence, first.node, first.variant) + Uuid.from(first.versionNumber, -1, first.clockSequence, first.node, first.variant) } assertFailsWith { - UUID(first.versionNumber, first.timeStamp, -1, first.node, first.variant) + Uuid.from(first.versionNumber, first.timeStamp, -1, first.node, first.variant) } assertFailsWith { - UUID(first.versionNumber, first.timeStamp, first.clockSequence, -1, first.variant) + Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, -1, first.variant) } assertFailsWith { - UUID(first.versionNumber, first.timeStamp, first.clockSequence, first.node, -1) + Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, first.node, -1) } } - @Test - fun testComparison() { - assertEquals(UUID(UUID_STRING), UUID(UUID_STRING)) - assertNotEquals(UUID(UUID_STRING), UUID(UUID_STRING2)) - assertNotEquals(UUID(UUID_STRING), UUID(UUID_STRING3)) - - assertTrue(UUID(UUID_STRING) < UUID(UUID_STRING2)) - assertTrue(UUID(UUID_STRING) < UUID(UUID_STRING3)) - assertTrue(UUID(UUID_STRING3) > UUID(UUID_STRING2)) - - assertEquals( - listOf(UUID(UUID_STRING), UUID(UUID_STRING2), UUID(UUID_STRING3)), - listOf(UUID(UUID_STRING2), UUID(UUID_STRING3), UUID(UUID_STRING)).sorted() - ) - - assertFalse(UUID(UUID_STRING).equals(UUID_STRING)) - } - @Test fun testVariants() { - assertEquals(0, UUID("1b3e4567-e99b-13d3-0476-446657420000").variant) - assertEquals(1, UUID("1b3e4567-e99b-13d3-2476-446657420000").variant) - assertEquals(2, UUID("1b3e4567-e99b-13d3-4476-446657420000").variant) - assertEquals(3, UUID("1b3e4567-e99b-13d3-6476-446657420000").variant) - assertEquals(4, UUID("1b3e4567-e99b-13d3-8476-446657420000").variant) - assertEquals(5, UUID("1b3e4567-e99b-13d3-a476-446657420000").variant) - assertEquals(7, UUID("1b3e4567-e99b-13d3-e476-446657420000").variant) + assertEquals(0, Uuid.parse("1b3e4567-e99b-13d3-0476-446657420000").variant) + assertEquals(1, Uuid.parse("1b3e4567-e99b-13d3-2476-446657420000").variant) + assertEquals(2, Uuid.parse("1b3e4567-e99b-13d3-4476-446657420000").variant) + assertEquals(3, Uuid.parse("1b3e4567-e99b-13d3-6476-446657420000").variant) + assertEquals(4, Uuid.parse("1b3e4567-e99b-13d3-8476-446657420000").variant) + assertEquals(5, Uuid.parse("1b3e4567-e99b-13d3-a476-446657420000").variant) + assertEquals(7, Uuid.parse("1b3e4567-e99b-13d3-e476-446657420000").variant) } @Test fun testVersionNumbers() { - assertEquals(1, UUID("1b3e4567-e99b-13d3-a476-446657420000").versionNumber) - assertEquals(2, UUID("1b3e4567-e99b-23d3-a476-446657420000").versionNumber) - assertEquals(3, UUID("1b3e4567-e99b-33d3-a476-446657420000").versionNumber) - assertEquals(4, UUID("1b3e4567-e99b-43d3-a476-446657420000").versionNumber) - assertEquals(5, UUID("1b3e4567-e99b-53d3-a476-446657420000").versionNumber) - assertEquals(0xf, UUID("1b3e4567-e99b-f3d3-a476-446657420000").versionNumber) - } - - @Test - fun testVersions() { - assertEquals(UUID.Version.TIME_BASED, UUID("1b3e4567-e99b-13d3-a476-446657420000").version) - assertEquals(UUID.Version.DCE_SECURITY, UUID("1b3e4567-e99b-23d3-a476-446657420000").version) - assertEquals(UUID.Version.NAME_BASED_MD5, UUID("1b3e4567-e99b-33d3-a476-446657420000").version) - assertEquals(UUID.Version.RANDOM_BASED, UUID("1b3e4567-e99b-43d3-a476-446657420000").version) - assertEquals(UUID.Version.NAME_BASED_SHA1, UUID("1b3e4567-e99b-53d3-a476-446657420000").version) - } - - @Test - @Suppress("DEPRECATION") - fun testMigrationDeprecations() { - assertEquals(UUID.fromString(SOME_UUID_STRING), UUID(SOME_UUID_STRING)) - - @Suppress("DEPRECATION_ERROR") - UUID.randomUUID() - - @Suppress("DEPRECATION_ERROR") - UUID.nameUUIDFromBytes(byteArrayOf()) - - @Suppress("DEPRECATION_ERROR") - with(UUID(SOME_UUID_STRING)) { - assertEquals(timeStampAndVersionRaw, getMostSignificantBits()) - assertEquals(clockSequenceVariantAndNodeRaw, getLeastSignificantBits()) - } + assertEquals(1, Uuid.parse("1b3e4567-e99b-13d3-a476-446657420000").versionNumber) + assertEquals(2, Uuid.parse("1b3e4567-e99b-23d3-a476-446657420000").versionNumber) + assertEquals(3, Uuid.parse("1b3e4567-e99b-33d3-a476-446657420000").versionNumber) + assertEquals(4, Uuid.parse("1b3e4567-e99b-43d3-a476-446657420000").versionNumber) + assertEquals(5, Uuid.parse("1b3e4567-e99b-53d3-a476-446657420000").versionNumber) + assertEquals(0xf, Uuid.parse("1b3e4567-e99b-f3d3-a476-446657420000").versionNumber) } @Test fun testIsValidString() { - assertTrue(UUID.isValidUUIDString(SOME_UUID_STRING)) - assertTrue(UUID.isValidUUIDString("{$SOME_UUID_STRING}")) - assertTrue(UUID.isValidUUIDString(" {$SOME_UUID_STRING}")) - assertTrue(UUID.isValidUUIDString(" {$SOME_UUID_STRING} ")) - - assertFalse(UUID.isValidUUIDString(SOME_UUID_STRING.drop(1))) - assertFalse(UUID.isValidUUIDString(SOME_UUID_STRING.dropLast(1))) - assertFalse(UUID.isValidUUIDString(SOME_UUID_STRING.replace('b', 'X'))) + assertTrue(Uuid.isValidUUIDString(SOME_UUID_STRING)) + + assertFalse(Uuid.isValidUUIDString(SOME_UUID_STRING.drop(1))) + assertFalse(Uuid.isValidUUIDString(SOME_UUID_STRING.dropLast(1))) + assertFalse(Uuid.isValidUUIDString(SOME_UUID_STRING.replace('b', 'X'))) assertNull(SOME_UUID_STRING.drop(1).toUUIDOrNull()) } @Test fun testRandomCreation() { - assertEquals(UUID.Version.RANDOM_BASED, UUID().version) - assertEquals(UUID.Version.RANDOM_BASED, SecureRandom.nextUUID().version) + assertEquals(4, Uuid.random().versionNumber) + assertEquals(4, Random.nextUuid().versionNumber) } } diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/UUIDv7Test.kt b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/UUIDv7Test.kt index ac3a68b..b815a2b 100644 --- a/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/UUIDv7Test.kt +++ b/kotlinx-uuid-core/src/commonTest/kotlin/kotlinx/uuid/UUIDv7Test.kt @@ -3,7 +3,6 @@ package kotlinx.uuid import kotlin.random.Random import kotlin.test.* -@UUIDExperimentalAPI class UUIDv7Test { @Test fun test() { @@ -13,7 +12,7 @@ class UUIDv7Test { assertEquals(1645557742000, one.unixTimeStamp) assertEquals(1645557742000, two.unixTimeStamp) - assertEquals("017f22e2-79b0-7493-a342-1cdb22b5d84b", one.toString()) + assertEquals("017f22e2-79b0-7b35-ab5c-c2334bd875e2", one.toString()) assertEquals(7, one.versionNumber) } } diff --git a/kotlinx-uuid-core/src/jsMain/kotlin/kotlinx/uuid/SecureRandom.js.kt b/kotlinx-uuid-core/src/jsMain/kotlin/kotlinx/uuid/SecureRandom.js.kt deleted file mode 100644 index bfdb48d..0000000 --- a/kotlinx-uuid-core/src/jsMain/kotlin/kotlinx/uuid/SecureRandom.js.kt +++ /dev/null @@ -1,57 +0,0 @@ -package kotlinx.uuid - -import kotlinx.browser.* -import kotlinx.uuid.internal.* -import org.khronos.webgl.* -import org.w3c.dom.* -import kotlin.random.* - -private val isNode = - js("typeof process !== 'undefined' && process.versions != null && process.versions.node != null") as Boolean - -public actual val SecureRandom: Random = if (isNode) SecureRandomNode else SecureRandomBrowser - -private external interface Crypto { - fun getRandomValues(array: Uint32Array): Uint32Array -} - -private object SecureRandomBrowser : Random() { - private inline val Window.crypto: Crypto - get() = asDynamic().crypto.unsafeCast() - - override fun nextBits(bitCount: Int): Int = - nextInt().takeUpperBits(bitCount) - - override fun nextLong(): Long { - val randomInts = window.crypto.getRandomValues(Uint32Array(2)) - return ((randomInts[0].toULong() shl Int.SIZE_BITS) + randomInts[1].toULong()).toLong() - } - - override fun nextInt(): Int = window.crypto.getRandomValues(Uint32Array(1))[0] - - /** - * Copied from [stdLib][kotlin.random.takeUpperBits] - */ - private fun Int.takeUpperBits(bitCount: Int): Int = - this.ushr(32 - bitCount) and (-bitCount).shr(31) -} - -private external interface CryptoNode { - fun randomInt(max: Int): Int - fun randomBytes(bytes: Int): ArrayBuffer -} - -private object SecureRandomNode : Random() { - @Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE") - val crypto: CryptoNode = js("eval('require')('crypto')") as CryptoNode - - override fun nextBits(bitCount: Int): Int { - val numberOfBytes = (bitCount + Byte.SIZE_BITS) / Byte.SIZE_BITS - val random = crypto.randomBytes(numberOfBytes) - return Int8Array(random).unsafeCast().toInt() - } - - override fun nextInt(): Int { - return crypto.randomInt(max = Int.MAX_VALUE) - } -} diff --git a/kotlinx-uuid-core/src/jsMain/kotlin/kotlinx/uuid/internal/CommonParcelable.js.kt b/kotlinx-uuid-core/src/jsMain/kotlin/kotlinx/uuid/internal/CommonParcelable.js.kt deleted file mode 100644 index 76c06b9..0000000 --- a/kotlinx-uuid-core/src/jsMain/kotlin/kotlinx/uuid/internal/CommonParcelable.js.kt +++ /dev/null @@ -1,3 +0,0 @@ -package kotlinx.uuid.internal - -public actual interface CommonParcelable diff --git a/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/Converting.kt b/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/Converting.kt index 1268194..9d18af4 100644 --- a/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/Converting.kt +++ b/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/Converting.kt @@ -3,15 +3,16 @@ */ package kotlinx.uuid +import kotlin.uuid.Uuid /** - * Converts this [java.util.UUID][java.util.UUID] value to a [kotlinx.uuid.UUID][UUID] value + * Converts this [java.util.UUID][java.util.UUID] value to a [kotlin.uuid.Uuid][Uuid] value * by using the default [toString] representation. */ -public fun java.util.UUID.toKotlinUUID(): UUID = UUID(toString()) +public fun java.util.UUID.toKotlinUuid(): Uuid = Uuid.parse(toString()) /** - * Converts this [kotlinx.uuid.UUID][UUID] value to a [java.util.UUID][java.util.UUID] value + * Converts this [kotlin.uuid.Uuid][Uuid] value to a [java.util.UUID][java.util.UUID] value * by using the default [toString] representation. */ -public fun UUID.toJavaUUID(): java.util.UUID = java.util.UUID.fromString(toString()) +public fun Uuid.toJavaUUID(): java.util.UUID = java.util.UUID.fromString(toString()) diff --git a/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/SecureRandom.kt b/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/SecureRandom.kt deleted file mode 100644 index 63648f1..0000000 --- a/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/SecureRandom.kt +++ /dev/null @@ -1,5 +0,0 @@ -package kotlinx.uuid - -import kotlin.random.* - -public actual val SecureRandom: Random = java.security.SecureRandom().asKotlinRandom() diff --git a/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/internal/CommonParcelable.jvm.kt b/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/internal/CommonParcelable.jvm.kt deleted file mode 100644 index 76c06b9..0000000 --- a/kotlinx-uuid-core/src/jvmMain/kotlin/kotlinx/uuid/internal/CommonParcelable.jvm.kt +++ /dev/null @@ -1,3 +0,0 @@ -package kotlinx.uuid.internal - -public actual interface CommonParcelable diff --git a/kotlinx-uuid-core/src/jvmTest/kotlin/kotlinx/uuid/JavaConvertingTest.kt b/kotlinx-uuid-core/src/jvmTest/kotlin/kotlinx/uuid/JavaConvertingTest.kt index 27989a1..c51da11 100644 --- a/kotlinx-uuid-core/src/jvmTest/kotlin/kotlinx/uuid/JavaConvertingTest.kt +++ b/kotlinx-uuid-core/src/jvmTest/kotlin/kotlinx/uuid/JavaConvertingTest.kt @@ -5,12 +5,13 @@ package kotlinx.uuid import kotlin.test.* +import kotlin.uuid.Uuid class JavaConvertingTest { @Test fun toJavaUUID() { - val kotlinUUID = UUID(SOME_UUID_STRING) + val kotlinUUID = Uuid.parse(SOME_UUID_STRING) val javaUUID = kotlinUUID.toJavaUUID() assertEquals(SOME_UUID_STRING, javaUUID.toString()) } @@ -18,7 +19,7 @@ class JavaConvertingTest { @Test fun fromJavaUUID() { val javaUUID = java.util.UUID.fromString(SOME_UUID_STRING) - val kotlinUUID = javaUUID.toKotlinUUID() + val kotlinUUID = javaUUID.toKotlinUuid() assertEquals(SOME_UUID_STRING, kotlinUUID.toString()) } } diff --git a/kotlinx-uuid-core/src/jvmTest/kotlin/kotlinx/uuid/JavaSpecificTests.kt b/kotlinx-uuid-core/src/jvmTest/kotlin/kotlinx/uuid/JavaSpecificTests.kt index 08b398b..cba2f8b 100644 --- a/kotlinx-uuid-core/src/jvmTest/kotlin/kotlinx/uuid/JavaSpecificTests.kt +++ b/kotlinx-uuid-core/src/jvmTest/kotlin/kotlinx/uuid/JavaSpecificTests.kt @@ -7,14 +7,15 @@ package kotlinx.uuid import java.security.* import kotlin.random.* import kotlin.test.* +import kotlin.uuid.Uuid class JavaSpecificTests { @Test fun secure() { - UUID.generateUUID(SecureRandom().asKotlinRandom()).assertRandomGenerated() + Uuid.random(SecureRandom().asKotlinRandom()).assertRandomGenerated() } - private fun UUID.assertRandomGenerated() { + private fun Uuid.assertRandomGenerated() { assertTrue(isRfcVariant) assertEquals(4, versionNumber) } diff --git a/kotlinx-uuid-core/src/linuxDerivatMain/kotlin/kotlinx/uuid/SecureRandom.linux.kt b/kotlinx-uuid-core/src/linuxDerivatMain/kotlin/kotlinx/uuid/SecureRandom.linux.kt deleted file mode 100644 index 207f994..0000000 --- a/kotlinx-uuid-core/src/linuxDerivatMain/kotlin/kotlinx/uuid/SecureRandom.linux.kt +++ /dev/null @@ -1,26 +0,0 @@ -package kotlinx.uuid - -import kotlinx.cinterop.* -import kotlinx.uuid.internal.* -import platform.posix.* -import kotlin.random.* - -public actual val SecureRandom: Random = DevUrandom() - -@OptIn(ExperimentalForeignApi::class) -private class DevUrandom : Random() { - @OptIn(UnsafeNumber::class) - override fun nextBits(bitCount: Int): Int { - require(bitCount > 0) - val numberOfBytes = (bitCount + Byte.SIZE_BITS) / Byte.SIZE_BITS - val bytes = ByteArray(size = numberOfBytes) - val urandom = open("/dev/urandom", O_RDONLY) - require(urandom >= 0) - val status = bytes.usePinned { - read(urandom, it.addressOf(0), numberOfBytes.convert()) - } - close(urandom) - require(status >= 0) - return bytes.toInt() - } -} diff --git a/kotlinx-uuid-core/src/linuxDerivatMain/kotlin/kotlinx/uuid/internal/CommonParcelable.linux.kt b/kotlinx-uuid-core/src/linuxDerivatMain/kotlin/kotlinx/uuid/internal/CommonParcelable.linux.kt deleted file mode 100644 index 76c06b9..0000000 --- a/kotlinx-uuid-core/src/linuxDerivatMain/kotlin/kotlinx/uuid/internal/CommonParcelable.linux.kt +++ /dev/null @@ -1,3 +0,0 @@ -package kotlinx.uuid.internal - -public actual interface CommonParcelable diff --git a/kotlinx-uuid-core/src/mingwX64Main/kotlin/kotlinx/uuid/SecureRandom.ming.kt b/kotlinx-uuid-core/src/mingwX64Main/kotlin/kotlinx/uuid/SecureRandom.ming.kt deleted file mode 100644 index 25f756a..0000000 --- a/kotlinx-uuid-core/src/mingwX64Main/kotlin/kotlinx/uuid/SecureRandom.ming.kt +++ /dev/null @@ -1,30 +0,0 @@ -package kotlinx.uuid - -import kotlinx.cinterop.* -import kotlinx.uuid.internal.* -import platform.windows.* -import kotlin.random.* - -public actual val SecureRandom: Random = BCryptRandom() - -@OptIn(ExperimentalForeignApi::class) -private class BCryptRandom : Random() { - override fun nextBits(bitCount: Int): Int { - require(bitCount > 0) - val numberOfBytes = (bitCount + Byte.SIZE_BITS) / Byte.SIZE_BITS - val bytes = ByteArray(size = numberOfBytes) - val status = bytes.usePinned { - BCryptGenRandom( - hAlgorithm = null, - pbBuffer = it.addressOf(0).reinterpret(), - cbBuffer = numberOfBytes.convert(), - dwFlags = BCRYPT_USE_SYSTEM_PREFERRED_RNG.convert() - ) - } - - require(status == NTSTATUS_SUCCESS) - return bytes.toInt() - } -} - -private const val NTSTATUS_SUCCESS: NTSTATUS = 0 diff --git a/kotlinx-uuid-core/src/mingwX64Main/kotlin/kotlinx/uuid/internal/CommonParcelable.ming.kt b/kotlinx-uuid-core/src/mingwX64Main/kotlin/kotlinx/uuid/internal/CommonParcelable.ming.kt deleted file mode 100644 index 76c06b9..0000000 --- a/kotlinx-uuid-core/src/mingwX64Main/kotlin/kotlinx/uuid/internal/CommonParcelable.ming.kt +++ /dev/null @@ -1,3 +0,0 @@ -package kotlinx.uuid.internal - -public actual interface CommonParcelable diff --git a/kotlinx-uuid-datetime/api/kotlinx-uuid-datetime.api b/kotlinx-uuid-datetime/api/kotlinx-uuid-datetime.api index ddfcd26..44bd723 100644 --- a/kotlinx-uuid-datetime/api/kotlinx-uuid-datetime.api +++ b/kotlinx-uuid-datetime/api/kotlinx-uuid-datetime.api @@ -1,6 +1,6 @@ public final class kotlinx/uuid/datetime/DslKt { - public static final fun UUIDv7 (Lkotlinx/datetime/Instant;Lkotlin/random/Random;)Lkotlinx/uuid/UUID; - public static synthetic fun UUIDv7$default (Lkotlinx/datetime/Instant;Lkotlin/random/Random;ILjava/lang/Object;)Lkotlinx/uuid/UUID; - public static final fun getInstant (Lkotlinx/uuid/UUID;)Lkotlinx/datetime/Instant; + public static final fun UUIDv7 (Lkotlinx/datetime/Instant;Lkotlin/random/Random;)Lkotlin/uuid/Uuid; + public static synthetic fun UUIDv7$default (Lkotlinx/datetime/Instant;Lkotlin/random/Random;ILjava/lang/Object;)Lkotlin/uuid/Uuid; + public static final fun getInstant (Lkotlin/uuid/Uuid;)Lkotlinx/datetime/Instant; } diff --git a/kotlinx-uuid-datetime/src/commonMain/kotlin/kotlinx/uuid/datetime/Dsl.kt b/kotlinx-uuid-datetime/src/commonMain/kotlin/kotlinx/uuid/datetime/Dsl.kt index 572192b..6ee5c2e 100644 --- a/kotlinx-uuid-datetime/src/commonMain/kotlin/kotlinx/uuid/datetime/Dsl.kt +++ b/kotlinx-uuid-datetime/src/commonMain/kotlin/kotlinx/uuid/datetime/Dsl.kt @@ -2,19 +2,15 @@ package kotlinx.uuid.datetime import kotlinx.datetime.Clock import kotlinx.datetime.Instant -import kotlinx.uuid.SecureRandom -import kotlinx.uuid.UUID -import kotlinx.uuid.UUIDExperimentalAPI import kotlinx.uuid.UUIDv7 import kotlinx.uuid.unixTimeStamp import kotlin.random.Random +import kotlin.uuid.Uuid -@UUIDExperimentalAPI -public fun UUIDv7(timeStamp: Instant = Clock.System.now(), random: Random = SecureRandom): UUID = +public fun UUIDv7(timeStamp: Instant = Clock.System.now(), random: Random): Uuid = UUIDv7(timeStamp = timeStamp.toEpochMilliseconds(), random = random) /** * The UUIDv7 48 bit big-endian unsigned number of Unix epoch timestamp in milliseconds */ -@UUIDExperimentalAPI -public val UUID.instant: Instant get() = Instant.fromEpochMilliseconds(unixTimeStamp) +public val Uuid.instant: Instant get() = Instant.fromEpochMilliseconds(unixTimeStamp) diff --git a/kotlinx-uuid-datetime/src/commonTest/kotlin/kotlinx/uuid/datetime/InstantTest.kt b/kotlinx-uuid-datetime/src/commonTest/kotlin/kotlinx/uuid/datetime/InstantTest.kt index ba2e95d..d1ecae2 100644 --- a/kotlinx-uuid-datetime/src/commonTest/kotlin/kotlinx/uuid/datetime/InstantTest.kt +++ b/kotlinx-uuid-datetime/src/commonTest/kotlin/kotlinx/uuid/datetime/InstantTest.kt @@ -1,12 +1,11 @@ package kotlinx.uuid.datetime import kotlinx.datetime.Instant -import kotlinx.uuid.UUIDExperimentalAPI +import kotlinx.uuid.versionNumber import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals -@OptIn(UUIDExperimentalAPI::class) class InstantTest { @Test @@ -14,7 +13,7 @@ class InstantTest { val timestamp = Instant.parse("2020-02-20T10:21:42Z") val uuid = UUIDv7(timeStamp = timestamp, random = Random(4242)) assertEquals(timestamp, uuid.instant) - assertEquals("0170621e-0ef0-7493-a342-1cdb22b5d84b", uuid.toString()) + assertEquals("0170621e-0ef0-7b35-ab5c-c2334bd875e2", uuid.toString()) assertEquals(7, uuid.versionNumber) } } diff --git a/kotlinx-uuid-exposed/README.md b/kotlinx-uuid-exposed/README.md deleted file mode 100644 index c914793..0000000 --- a/kotlinx-uuid-exposed/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Module kotlinx-uuid-exposed - -[Exposed](https://github.com/JetBrains/Exposed) is an ORM framework for Kotlin. It has support for `java.util.UUID`, but -to get kotlin-uuid supported you need to include the corresponding dependency and use DSL functions: - -```kotlin -dependencies { - implementation("app.softwork:kotlinx-uuid-exposed:LATEST") -} -``` - -When declaring a table having UUID as Primary Key: - -```kotlin -// SQL DSL -object MyTable : KotlinxUUIDTable() { - // there is "id" property with the kotlin-uud type -} - -// DAO API -class MyTableEntity(id: EntityID) : KotlinxUUIDEntity(id) { - companion object : KotlinxUUIDEntityClass(MyTable) - -} -``` - -To declare a regular column, use `kotlinxUUID` function: - -```kotlin -object MyTable : Table() { - val something = kotlinxUUID("SOME_COLUMN") -} -``` - -Unfortunately, there is a function called `uuid` in the base class, inside Exposed, this is why we can't -overwrite/override it, so it may lead to confusion. The function `uuid` only works with `java.util.UUID`: - -```kotlin -object MyTable : Table() { - val column1 = kotlinxUUID("C1") // kotlinx.uuid.UUID - val column2 = uuid("C2") // java.util.UUID -} -``` diff --git a/kotlinx-uuid-exposed/api/kotlinx-uuid-exposed.api b/kotlinx-uuid-exposed/api/kotlinx-uuid-exposed.api deleted file mode 100644 index 80ae5ee..0000000 --- a/kotlinx-uuid-exposed/api/kotlinx-uuid-exposed.api +++ /dev/null @@ -1,34 +0,0 @@ -public final class kotlinx/uuid/exposed/DslKt { - public static final fun autoGenerate (Lorg/jetbrains/exposed/sql/Column;Lkotlin/random/Random;)Lorg/jetbrains/exposed/sql/Column; - public static synthetic fun autoGenerate$default (Lorg/jetbrains/exposed/sql/Column;Lkotlin/random/Random;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/Column; - public static final fun kotlinxUUID (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/String;)Lorg/jetbrains/exposed/sql/Column; -} - -public class kotlinx/uuid/exposed/KotlinxUUIDEntity : org/jetbrains/exposed/dao/Entity { - public fun (Lorg/jetbrains/exposed/dao/id/EntityID;)V -} - -public class kotlinx/uuid/exposed/KotlinxUUIDEntityClass : org/jetbrains/exposed/dao/EntityClass { - public fun (Lorg/jetbrains/exposed/dao/id/IdTable;Ljava/lang/Class;Lkotlin/jvm/functions/Function1;)V - public synthetic fun (Lorg/jetbrains/exposed/dao/id/IdTable;Ljava/lang/Class;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V -} - -public class kotlinx/uuid/exposed/KotlinxUUIDTable : org/jetbrains/exposed/dao/id/IdTable { - public fun ()V - public fun (Ljava/lang/String;Ljava/lang/String;Lkotlin/random/Random;)V - public synthetic fun (Ljava/lang/String;Ljava/lang/String;Lkotlin/random/Random;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun getId ()Lorg/jetbrains/exposed/sql/Column; - public fun getPrimaryKey ()Lorg/jetbrains/exposed/sql/Table$PrimaryKey; -} - -public final class kotlinx/uuid/exposed/UUIDColumnType : org/jetbrains/exposed/sql/ColumnType { - public fun ()V - public synthetic fun nonNullValueToString (Ljava/lang/Object;)Ljava/lang/String; - public fun nonNullValueToString (Lkotlinx/uuid/UUID;)Ljava/lang/String; - public synthetic fun notNullValueToDB (Ljava/lang/Object;)Ljava/lang/Object; - public fun notNullValueToDB (Lkotlinx/uuid/UUID;)Ljava/lang/Object; - public fun sqlType ()Ljava/lang/String; - public synthetic fun valueFromDB (Ljava/lang/Object;)Ljava/lang/Object; - public fun valueFromDB (Ljava/lang/Object;)Lkotlinx/uuid/UUID; -} - diff --git a/kotlinx-uuid-exposed/build.gradle.kts b/kotlinx-uuid-exposed/build.gradle.kts deleted file mode 100644 index 5c8d3f8..0000000 --- a/kotlinx-uuid-exposed/build.gradle.kts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2020-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - * Copyright 2021 hfhbd and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -plugins { - id("kotlinJvm") - id("publish") - id("dokkaLicensee") - id("kover") -} - -kotlin.jvmToolchain(11) - -dependencies { - api(projects.kotlinxUuidCore) - api(libs.exposed.dao) - - testImplementation(kotlin("test-junit")) - testRuntimeOnly(libs.exposed.jdbc) - testRuntimeOnly(libs.h2) - testRuntimeOnly(libs.slf4j) -} - -licensee { - allow("MIT") -} - -publishing { - publications.register("maven") { - from(components["java"]) - } -} - -java { - withJavadocJar() - withSourcesJar() -} diff --git a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/Dsl.kt b/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/Dsl.kt deleted file mode 100644 index b81f1ba..0000000 --- a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/Dsl.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid.exposed - -import kotlinx.uuid.* -import org.jetbrains.exposed.sql.* -import kotlin.random.Random - -/** - * Creates a binary column, with the specified [name], for storing UUIDs. - * Unlike the [Table.uuid] function, this one registers [kotlinx.uuid.UUID] type instead of [java.util.UUID]. - **/ -public fun Table.kotlinxUUID(name: String): Column { - return registerColumn(name, UUIDColumnType()) -} - -/** - * Configure column to generate UUID via [UUID.Companion.generateUUID] - * with the specified [random] that is backed by [SecureRandom] by default. - * Remember that using a [SecureRandom] may require to seed the system random source - * otherwise a system may get stuck. - **/ -public fun Column.autoGenerate(random: Random = SecureRandom): Column = apply { - defaultValueFun = { random.nextUUID() } -} diff --git a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDEntity.kt b/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDEntity.kt deleted file mode 100644 index e6d0c49..0000000 --- a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDEntity.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid.exposed - -import kotlinx.uuid.* -import org.jetbrains.exposed.dao.* -import org.jetbrains.exposed.dao.id.EntityID - -/** - * A [UUID](Kotlinx.uuid.UUID) DAO Entity for using the Exposed DAO API. - */ -public open class KotlinxUUIDEntity(id: EntityID) : Entity(id) diff --git a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDEntityClass.kt b/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDEntityClass.kt deleted file mode 100644 index 0707329..0000000 --- a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDEntityClass.kt +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid.exposed - -import kotlinx.uuid.* -import org.jetbrains.exposed.dao.* -import org.jetbrains.exposed.dao.id.* - -/** - * A [UUID](Kotlinx.uuid.UUID) DAO EntityClass for using the Exposed DAO API. - */ -public open class KotlinxUUIDEntityClass( - table: IdTable, - entityType: Class? = null, - entityCtor: ((EntityID) -> E)? = null -) : EntityClass(table, entityType, entityCtor) diff --git a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDTable.kt b/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDTable.kt deleted file mode 100644 index f7c430c..0000000 --- a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/KotlinxUUIDTable.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid.exposed - -import kotlinx.uuid.* -import org.jetbrains.exposed.dao.id.* -import org.jetbrains.exposed.sql.* - -/** - * Identity table with a key column having type [UUID]. Unique identifiers are generated before - * insertion by [UUID.Companion.generateUUID] with [SecureRandom] by default. - * - * @param name of the table. - * @param columnName for a primary key column, `"id"` by default. - * @param random is used to generate unique UUIDs. - */ -public open class KotlinxUUIDTable( - name: String = "", - columnName: String = "id", - random: kotlin.random.Random = SecureRandom -) : IdTable(name) { - override val id: Column> = kotlinxUUID(columnName) - .autoGenerate(random) - .entityId() - - override val primaryKey: PrimaryKey by lazy { super.primaryKey ?: PrimaryKey(id) } -} diff --git a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/UUIDColumnType.kt b/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/UUIDColumnType.kt deleted file mode 100644 index adff91d..0000000 --- a/kotlinx-uuid-exposed/src/main/kotlin/kotlinx/uuid/exposed/UUIDColumnType.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid.exposed - -import kotlinx.uuid.* -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.vendors.* -import java.nio.* - -/** - * A [UUID] column type for registering in exposed tables. - * @see kotlinxUUID to see how it is used - */ -public class UUIDColumnType : ColumnType() { - override fun sqlType(): String = currentDialect.dataTypeProvider.uuidType() - - override fun valueFromDB(value: Any): UUID = when { - value is java.util.UUID -> value.toKotlinUUID() - value is UUID -> value - value is ByteArray -> ByteBuffer.wrap(value).let { b -> valueFromDB(java.util.UUID(b.long, b.long)) } - value is String && UUID.isValidUUIDString(value) -> UUID(value) - value is String -> valueFromDB(value.toByteArray()) - else -> error("Unexpected value of type UUID: $value of ${value::class.qualifiedName}") - } - - override fun notNullValueToDB(value: UUID): Any = currentDialect.dataTypeProvider.uuidToDB(valueToUUID(value)) - - override fun nonNullValueToString(value: UUID): String = "'${valueToUUID(value)}'" - - internal fun valueToUUID(value: Any): java.util.UUID = when (value) { - is java.util.UUID -> value - is UUID -> value.toJavaUUID() - is String -> java.util.UUID.fromString(value) - is ByteArray -> ByteBuffer.wrap(value).let { java.util.UUID(it.long, it.long) } - else -> error("Unexpected value of type UUID: ${value.javaClass.canonicalName}") - } -} diff --git a/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDColumnTypeTest.kt b/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDColumnTypeTest.kt deleted file mode 100644 index aac2107..0000000 --- a/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDColumnTypeTest.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid.exposed - -import kotlinx.uuid.* -import java.nio.* -import kotlin.test.* - -class UUIDColumnTypeTest { - private val type = UUIDColumnType() - private val uuid = UUID.generateUUID() - - @Suppress("DEPRECATION_ERROR") - private val uuidBytes = ByteBuffer.allocate(16)!!.apply { - putLong(uuid.getMostSignificantBits()) - putLong(uuid.getLeastSignificantBits()) - }.array() - - @Test - fun testConversionJava() { - val result = type.valueFromDB(uuid.toJavaUUID()) - assertEquals(uuid, result) - - assertEquals(uuid, type.valueToUUID(uuid.toJavaUUID()).toKotlinUUID()) - assertEquals(uuid, type.valueToUUID(uuid).toKotlinUUID()) - } - - @Test - fun testPassThrough() { - assertEquals(uuid, type.valueFromDB(type.valueToUUID(uuid))) - } - - @Test - fun testByteArray() { - assertEquals(uuid.toJavaUUID(), type.valueToUUID(uuidBytes)) - assertEquals(uuid, type.valueFromDB(uuidBytes)) - } - - @Test - fun testString() { - assertEquals(uuid.toJavaUUID(), type.valueToUUID(uuid.toString())) - assertEquals(uuid, type.valueFromDB(uuid.toString())) - } -} diff --git a/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDDaoTests.kt b/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDDaoTests.kt deleted file mode 100644 index 044d7f1..0000000 --- a/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDDaoTests.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid.exposed - -import kotlinx.uuid.* -import org.jetbrains.exposed.dao.id.* -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.* -import kotlin.test.* - -class UUIDDaoTests { - - @Test - fun smokeTestWithH2() { - val db = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") - transaction(db) { - SchemaUtils.create(TestTables) - assertTrue(TestTables.exists()) - assertTrue(TestTable.all().toList().isEmpty()) - val newId = TestTable.new { }.id.value - assertNotNull(newId) - assertEquals(newId, TestTable[newId].id.value) - } - } - - object TestTables : KotlinxUUIDTable() - - class TestTable(id: EntityID) : KotlinxUUIDEntity(id) { - companion object : KotlinxUUIDEntityClass(TestTables) - } -} diff --git a/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDTableTest.kt b/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDTableTest.kt deleted file mode 100644 index 2906246..0000000 --- a/kotlinx-uuid-exposed/src/test/kotlin/kotlinx/uuid/exposed/UUIDTableTest.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.uuid.exposed - -import kotlinx.uuid.* -import org.jetbrains.exposed.dao.id.* -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.* -import kotlin.random.Random -import kotlin.test.* - -class UUIDTableTest { - @Test - fun smokeTest() { - assertTrue(TestTable.columns.isNotEmpty()) - val id: Column> = TestTable.id - assertEquals("id", id.name) - val random = id.defaultValueFun!!() - val uuid = random.value - assertNotNull(uuid) - assertNotEquals(UUID.NIL, uuid) - } - - @Test - fun smokeTestWithH2() { - val db = Database.connect("jdbc:h2:mem:smokeTestWithH2${Random.nextInt(0, 10000)}", "org.h2.Driver") - transaction(db) { - SchemaUtils.create(TestTable) - assertTrue(TestTable.exists()) - val uuid = TestTable.insert {}[TestTable.id].value - assertNotNull(uuid) - - val row = TestTable.selectAll().where { - TestTable.id eq uuid - }.single() - - assertNotNull(row) - assertEquals(uuid, row[TestTable.id].value) - } - } - - object TestTable : KotlinxUUIDTable() -} diff --git a/kotlinx-uuid-sqldelight/api/kotlinx-uuid-sqldelight.api b/kotlinx-uuid-sqldelight/api/kotlinx-uuid-sqldelight.api index 65a7bea..e798bf8 100644 --- a/kotlinx-uuid-sqldelight/api/kotlinx-uuid-sqldelight.api +++ b/kotlinx-uuid-sqldelight/api/kotlinx-uuid-sqldelight.api @@ -1,16 +1,16 @@ -public final class kotlinx/uuid/sqldelight/UUIDByteArrayAdapter : app/cash/sqldelight/ColumnAdapter { - public static final field INSTANCE Lkotlinx/uuid/sqldelight/UUIDByteArrayAdapter; +public final class kotlinx/uuid/sqldelight/UuidByteArrayAdapter : app/cash/sqldelight/ColumnAdapter { + public static final field INSTANCE Lkotlinx/uuid/sqldelight/UuidByteArrayAdapter; public synthetic fun decode (Ljava/lang/Object;)Ljava/lang/Object; - public fun decode ([B)Lkotlinx/uuid/UUID; + public fun decode ([B)Lkotlin/uuid/Uuid; public synthetic fun encode (Ljava/lang/Object;)Ljava/lang/Object; - public fun encode (Lkotlinx/uuid/UUID;)[B + public fun encode (Lkotlin/uuid/Uuid;)[B } -public final class kotlinx/uuid/sqldelight/UUIDStringAdapter : app/cash/sqldelight/ColumnAdapter { - public static final field INSTANCE Lkotlinx/uuid/sqldelight/UUIDStringAdapter; +public final class kotlinx/uuid/sqldelight/UuidStringAdapter : app/cash/sqldelight/ColumnAdapter { + public static final field INSTANCE Lkotlinx/uuid/sqldelight/UuidStringAdapter; public synthetic fun decode (Ljava/lang/Object;)Ljava/lang/Object; - public fun decode (Ljava/lang/String;)Lkotlinx/uuid/UUID; + public fun decode (Ljava/lang/String;)Lkotlin/uuid/Uuid; public synthetic fun encode (Ljava/lang/Object;)Ljava/lang/Object; - public fun encode (Lkotlinx/uuid/UUID;)Ljava/lang/String; + public fun encode (Lkotlin/uuid/Uuid;)Ljava/lang/String; } diff --git a/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UUIDByteArrayAdapter.kt b/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UUIDByteArrayAdapter.kt deleted file mode 100644 index 8a51319..0000000 --- a/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UUIDByteArrayAdapter.kt +++ /dev/null @@ -1,9 +0,0 @@ -package kotlinx.uuid.sqldelight - -import app.cash.sqldelight.* -import kotlinx.uuid.* - -public object UUIDByteArrayAdapter : ColumnAdapter { - override fun decode(databaseValue: ByteArray): UUID = UUID(databaseValue) - override fun encode(value: UUID): ByteArray = value.encodeToByteArray() -} diff --git a/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UUIDStringAdapter.kt b/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UUIDStringAdapter.kt deleted file mode 100644 index f7885e8..0000000 --- a/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UUIDStringAdapter.kt +++ /dev/null @@ -1,9 +0,0 @@ -package kotlinx.uuid.sqldelight - -import app.cash.sqldelight.* -import kotlinx.uuid.* - -public object UUIDStringAdapter : ColumnAdapter { - override fun decode(databaseValue: String): UUID = UUID(databaseValue) - override fun encode(value: UUID): String = value.toString(false) -} diff --git a/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UuidByteArrayAdapter.kt b/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UuidByteArrayAdapter.kt new file mode 100644 index 0000000..0322125 --- /dev/null +++ b/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UuidByteArrayAdapter.kt @@ -0,0 +1,9 @@ +package kotlinx.uuid.sqldelight + +import app.cash.sqldelight.* +import kotlin.uuid.Uuid + +public object UuidByteArrayAdapter : ColumnAdapter { + override fun decode(databaseValue: ByteArray): Uuid = Uuid.fromByteArray(databaseValue) + override fun encode(value: Uuid): ByteArray = value.toByteArray() +} diff --git a/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UuidStringAdapter.kt b/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UuidStringAdapter.kt new file mode 100644 index 0000000..79f30be --- /dev/null +++ b/kotlinx-uuid-sqldelight/src/commonMain/kotlin/kotlinx/uuid/sqldelight/UuidStringAdapter.kt @@ -0,0 +1,9 @@ +package kotlinx.uuid.sqldelight + +import app.cash.sqldelight.* +import kotlin.uuid.Uuid + +public object UuidStringAdapter : ColumnAdapter { + override fun decode(databaseValue: String): Uuid = Uuid.parse(databaseValue) + override fun encode(value: Uuid): String = value.toString() +} diff --git a/settings.gradle.kts b/settings.gradle.kts index e4b3eb0..2b33b2a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -38,6 +38,5 @@ enableFeaturePreview("STABLE_CONFIGURATION_CACHE") include(":kotlinx-uuid-core") -include(":kotlinx-uuid-exposed") include(":kotlinx-uuid-sqldelight") include(":kotlinx-uuid-datetime")