Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change package name to app.softwork #379

Merged
merged 5 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@
> #### This is a fork from https://github.com/cy6erGn0m/kotlinx-uuid, released under Apache 2.
> #### The main implementation was thankfully provided by [Sergey Mashkov (cy6erGn0m)](https://github.com/cy6erGn0m)!

`kotlinx-uuid` is a multiplatform (MPP) [Kotlin](https://kotlinlang.org) library introducing support
for [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier).
`kotlinx-uuid` adds helper methods to [Uuid](kotlin.uuid.Uuid) added to Kotlin stdlib starting 2.0.20.

- [Source code](https://github.com/hfhbd/kotlinx-uuid)
- [Docs](https://uuid.softwork.app)

The main class `UUID` is serializable out of the box, so the library depends
on [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization). If you don't need serialization, you don't
need to apply the plugin.

Supported platforms are `jvm`, `js(IR)` and all tier 1, 2 and 3 native targets.

## Install

This package is uploaded to `mavenCentral`.
Expand Down
59 changes: 32 additions & 27 deletions detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<SmellBaseline>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>FunctionNaming:Dsl.kt$public fun UUIDv7(timeStamp: Instant = Clock.System.now(), random: Random): Uuid</ID>
<ID>FunctionNaming:UUID7.kt$public fun UUIDv7(timeStamp: Long, random: Random): Uuid</ID>
<ID>FunctionNaming:Dsl.kt$public fun Uuidv7(timeStamp: Instant = Clock.System.now(), random: Random): Uuid</ID>
<ID>FunctionNaming:Uuidv7.kt$public fun Uuidv7(timeStamp: Long, random: Random): Uuid</ID>
<ID>MagicNumber:KotlinConfig.kt$8</ID>
<ID>MagicNumber:NameBasedGenerator.kt$0x3f</ID>
<ID>MagicNumber:NameBasedGenerator.kt$4</ID>
Expand Down Expand Up @@ -44,31 +44,36 @@
<ID>MagicNumber:SHA1.kt$SHA1.IntArrayView$3</ID>
<ID>MagicNumber:SHA1.kt$SHA1.IntArrayView$4</ID>
<ID>MagicNumber:SHA1.kt$SHA1.IntArrayView$8</ID>
<ID>MagicNumber:UUID.kt$0x0fffL</ID>
<ID>MagicNumber:UUID.kt$0x1fff</ID>
<ID>MagicNumber:UUID.kt$0xf000L</ID>
<ID>MagicNumber:UUID.kt$0xffff00000000L</ID>
<ID>MagicNumber:UUID.kt$0xffff0000L</ID>
<ID>MagicNumber:UUID.kt$0xffffffffffffL</ID>
<ID>MagicNumber:UUID.kt$12</ID>
<ID>MagicNumber:UUID.kt$13</ID>
<ID>MagicNumber:UUID.kt$15</ID>
<ID>MagicNumber:UUID.kt$16</ID>
<ID>MagicNumber:UUID.kt$32</ID>
<ID>MagicNumber:UUID.kt$4</ID>
<ID>MagicNumber:UUID.kt$48</ID>
<ID>MagicNumber:UUID.kt$5</ID>
<ID>MagicNumber:UUID.kt$60</ID>
<ID>MagicNumber:UUID.kt$61</ID>
<ID>MagicNumber:UUID.kt$7</ID>
<ID>MagicNumber:UUID7.kt$0x0fffL</ID>
<ID>MagicNumber:UUID7.kt$0xffff0000L</ID>
<ID>MagicNumber:UUID7.kt$16</ID>
<ID>MagicNumber:UUID7.kt$28672</ID>
<ID>MagicNumber:UUID7.kt$32</ID>
<ID>MagicNumber:UUID7.kt$4095</ID>
<ID>MagicNumber:UUID7.kt$48</ID>
<ID>MagicNumber:UUID7.kt$62</ID>
<ID>MagicNumber:Uuid.kt$0x0fffL</ID>
<ID>MagicNumber:Uuid.kt$0x1fff</ID>
<ID>MagicNumber:Uuid.kt$0xf000L</ID>
<ID>MagicNumber:Uuid.kt$0xffff00000000L</ID>
<ID>MagicNumber:Uuid.kt$0xffff0000L</ID>
<ID>MagicNumber:Uuid.kt$0xffffffffffffL</ID>
<ID>MagicNumber:Uuid.kt$12</ID>
<ID>MagicNumber:Uuid.kt$13</ID>
<ID>MagicNumber:Uuid.kt$15</ID>
<ID>MagicNumber:Uuid.kt$16</ID>
<ID>MagicNumber:Uuid.kt$32</ID>
<ID>MagicNumber:Uuid.kt$4</ID>
<ID>MagicNumber:Uuid.kt$48</ID>
<ID>MagicNumber:Uuid.kt$5</ID>
<ID>MagicNumber:Uuid.kt$60</ID>
<ID>MagicNumber:Uuid.kt$61</ID>
<ID>MagicNumber:Uuid.kt$7</ID>
<ID>MagicNumber:Uuidv7.kt$0x3F</ID>
<ID>MagicNumber:Uuidv7.kt$0x70</ID>
<ID>MagicNumber:Uuidv7.kt$0x80</ID>
<ID>MagicNumber:Uuidv7.kt$0xFF</ID>
<ID>MagicNumber:Uuidv7.kt$16</ID>
<ID>MagicNumber:Uuidv7.kt$24</ID>
<ID>MagicNumber:Uuidv7.kt$3</ID>
<ID>MagicNumber:Uuidv7.kt$32</ID>
<ID>MagicNumber:Uuidv7.kt$4</ID>
<ID>MagicNumber:Uuidv7.kt$40</ID>
<ID>MagicNumber:Uuidv7.kt$5</ID>
<ID>MagicNumber:Uuidv7.kt$6</ID>
<ID>MagicNumber:Uuidv7.kt$8</ID>
<ID>TooManyFunctions:SHA1.kt$SHA1</ID>
</CurrentIssues>
</SmellBaseline>
5 changes: 5 additions & 0 deletions gradle/build-logic/src/main/kotlin/dokkaLicensee.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ tasks.named<DokkaTaskPartial>("dokkaHtmlPartial") {
}
}
externalDocumentationLink("https://kotlinlang.org/api/kotlinx.serialization/")
externalDocumentationLink(
url = "https://kotlinlang.org/api/kotlinx-datetime/",
packageListUrl = "https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list",
)
externalDocumentationLink("https://cashapp.github.io/sqldelight/2.0.2/2.x/")
}
}

Expand Down
40 changes: 9 additions & 31 deletions kotlinx-uuid-core/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
# Module kotlinx-uuid-core

This core module contains the serializable UUID class.

## Creating from a UUID string

```kotlin
val uuid = UUID("1b3e4567-e99b-13d3-a476-446657420000")
val guid = UUID("{1b3e4567-e99b-13d3-a476-446657420000}")
```

## Generating UUID4 using random

```kotlin
// using a default SecureRandom implementation
val uuid = UUID()

// use custom Kotlin Random instance
val uuid = UUID.generateUUID(yourRandom)
```
This core module contains several helper methods for the [Uuid](kotlin.uuid.Uuid) class, like `timestamp`, `variant`,
`version`.

## Generating UUID5 using hash

`kotlinx-uuid` provides the ability to generate uuids by hashing names (Only SHA-1 is supported at the moment).

```kotlin
val appNamespace = UUID("my-app-uuid")
val agentId = UUID.generateUUID(appNamespace, "agentId")
val appNamespace = Uuid.parse("my-app-uuid")
val agentId = Uuid.generateUuid(appNamespace, "agentId")
```

The other alternative is to generate UUID by hashing bytes (similar to `java.util.UUID.nameUUIDFromBytes`).
The other alternative is to generate Uuid by hashing bytes (similar to `java.util.UUID.nameUUIDFromBytes`).

```kotlin
val uuid = UUID.generateUUID(bytes)
val uuid = Uuid.generateUUID(bytes)
```

> Note that unlike `java.util.UUID`, kotlinx's generateUUID
Expand All @@ -51,15 +35,9 @@ uuid.unixTimeStamp // 42

## Serializing (kotlinx.serialization)

There are two serializers for `UUID`: the default one and the binary.

The default serializer does always serialize UUIDs as string primitives.

```kotlin
Json.encodeToString(uuid) == "\"1b3e4567-e99b-13d3-a476-446657420000\""
```

The additional serializer is useful for binary formats. Because they are not human-readable, and it's possible to reduce
There is also a binary serializers for `Uuid`.
This additional serializer is useful for binary formats. Because they are not human-readable, and it's possible to
reduce
size.

```kotlin
Expand Down
32 changes: 16 additions & 16 deletions kotlinx-uuid-core/api/android/kotlinx-uuid-core.api
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
public final class kotlinx/uuid/BinarySerializer : kotlinx/serialization/KSerializer {
public static final field INSTANCE Lkotlinx/uuid/BinarySerializer;
public final class app/softwork/uuid/BinarySerializer : kotlinx/serialization/KSerializer {
public static final field INSTANCE Lapp/softwork/uuid/BinarySerializer;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
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;Lkotlin/uuid/Uuid;)V
}

public final class kotlinx/uuid/NameBasedGeneratorKt {
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 app/softwork/uuid/NameBasedGeneratorKt {
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 final class app/softwork/uuid/RandomGeneratorKt {
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;)Lkotlin/uuid/Uuid;
public static final fun getUnixTimeStamp (Lkotlin/uuid/Uuid;)J
}

public final class kotlinx/uuid/UUIDKt {
public final class app/softwork/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
Expand All @@ -31,13 +26,13 @@ public final class kotlinx/uuid/UUIDKt {
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 isValidUuidString (Lkotlin/uuid/Uuid$Companion;Ljava/lang/String;)Z
public static final fun toUuid (Ljava/lang/String;)Lkotlin/uuid/Uuid;
public static final fun toUuidOrNull (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 final class app/softwork/uuid/UuidParceler : kotlinx/parcelize/Parceler {
public static final field INSTANCE Lapp/softwork/uuid/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
Expand All @@ -49,3 +44,8 @@ public final class kotlinx/uuid/internal/UuidParceler : kotlinx/parcelize/Parcel
public fun write (Lkotlin/uuid/Uuid;Landroid/os/Parcel;I)V
}

public final class app/softwork/uuid/Uuidv7Kt {
public static final fun Uuidv7 (JLkotlin/random/Random;)Lkotlin/uuid/Uuid;
public static final fun getUnixTimeStamp (Lkotlin/uuid/Uuid;)J
}

30 changes: 15 additions & 15 deletions kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
public final class kotlinx/uuid/BinarySerializer : kotlinx/serialization/KSerializer {
public static final field INSTANCE Lkotlinx/uuid/BinarySerializer;
public final class app/softwork/uuid/BinarySerializer : kotlinx/serialization/KSerializer {
public static final field INSTANCE Lapp/softwork/uuid/BinarySerializer;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
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;Lkotlin/uuid/Uuid;)V
}

public final class kotlinx/uuid/ConvertingKt {
public final class app/softwork/uuid/ConvertingKt {
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 (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 app/softwork/uuid/NameBasedGeneratorKt {
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 final class app/softwork/uuid/RandomGeneratorKt {
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;)Lkotlin/uuid/Uuid;
public static final fun getUnixTimeStamp (Lkotlin/uuid/Uuid;)J
}

public final class kotlinx/uuid/UUIDKt {
public final class app/softwork/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
Expand All @@ -36,8 +31,13 @@ public final class kotlinx/uuid/UUIDKt {
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 isValidUuidString (Lkotlin/uuid/Uuid$Companion;Ljava/lang/String;)Z
public static final fun toUuid (Ljava/lang/String;)Lkotlin/uuid/Uuid;
public static final fun toUuidOrNull (Ljava/lang/String;)Lkotlin/uuid/Uuid;
}

public final class app/softwork/uuid/Uuidv7Kt {
public static final fun Uuidv7 (JLkotlin/random/Random;)Lkotlin/uuid/Uuid;
public static final fun getUnixTimeStamp (Lkotlin/uuid/Uuid;)J
}

2 changes: 1 addition & 1 deletion kotlinx-uuid-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ kotlin {
}

android {
namespace = "kotlinx.uuid"
namespace = "app.softwork.uuid"
compileSdk = 34

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package kotlinx.uuid.internal
package app.softwork.uuid.internal

import android.os.Parcel
import android.os.Parcelable
import app.softwork.uuid.*
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.TypeParceler
import kotlinx.parcelize.parcelableCreator
import kotlinx.uuid.*
import kotlin.test.*
import kotlin.uuid.Uuid

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kotlinx.uuid.internal
package app.softwork.uuid

import android.os.Parcel
import kotlinx.parcelize.Parceler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2020-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package app.softwork.uuid

import platform.Foundation.NSUUID
import kotlin.uuid.Uuid

/**
* Converts this [NSUUID] value to a [Uuid] value
* by using the [UUIDString](platform.Foundation.NSUUID.UUIDString) representation.
*/
public fun NSUUID.toKotlinUuid(): Uuid = Uuid.parse(UUIDString)

/**
* Converts this [Uuid] value to a [NSUUID] value
* by using the default [kotlin.uuid.Uuid.toString] representation.
*/
public fun Uuid.toNsUUID(): NSUUID = NSUUID(toString())
19 changes: 0 additions & 19 deletions kotlinx-uuid-core/src/appleMain/kotlin/kotlinx/uuid/Converter.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 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
package app.softwork.uuid

import kotlin.test.*
import kotlin.uuid.Uuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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
package app.softwork.uuid

import kotlinx.serialization.*
import kotlinx.serialization.builtins.*
Expand All @@ -13,9 +13,9 @@ import kotlin.uuid.Uuid
/**
* This serializer is useful with binary formats to reduce size. You may also use it with
* text formats like json, but it is not that useful (because there will be no size gain)
* and a serialized UUID is not human-readable.
* and a serialized Uuid is not human-readable.
*
* With this serializer, a UUID is represented as an array of long with two elements.
* With this serializer, a Uuid is represented as an array of long with two elements.
*
* Example:
* ```kotlin
Expand All @@ -35,7 +35,7 @@ public object BinarySerializer : KSerializer<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")
throw SerializationException("Uuid array should consist of 2 elements")
}

Uuid.fromLongs(array[0], array[1])
Expand Down
Loading
Loading