File tree Expand file tree Collapse file tree 10 files changed +59
-22
lines changed
android/library/src/main/java/io/appwrite
kotlin/src/main/kotlin/io/appwrite Expand file tree Collapse file tree 10 files changed +59
-22
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ import java.time.Instant
4
4
import kotlin.math.floor
5
5
import kotlin.random.Random
6
6
7
- fun uniqid(): String {
7
+ // Generate a unique ID based on timestamp
8
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
9
+ private fun uniqueId(): String {
8
10
val currentTimestamp = Instant.now().toEpochMilli() / 1000.0
9
11
val secondsPart = floor(currentTimestamp).toLong()
10
12
val microsecondsPart = ((currentTimestamp - secondsPart) * 1_000_000).toLong()
@@ -18,8 +20,11 @@ class ID {
18
20
companion object {
19
21
fun custom(id: String): String
20
22
= id
23
+
24
+ // Generate a unique ID with padding to have a longer ID
25
+ // Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
21
26
fun unique(padding: Int = 7): String {
22
- val baseId = uniqid ()
27
+ val baseId = uniqueId ()
23
28
val randomPadding = (1..padding)
24
29
.map { Random.nextInt(0, 16).toString(16) }
25
30
.joinToString("")
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ class ID {
6
6
7
7
// Generate a unique ID based on timestamp
8
8
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9
- static String _uniqid () {
9
+ static String _uniqueId () {
10
10
final now = DateTime.now();
11
11
final secondsSinceEpoch = (now.millisecondsSinceEpoch / 1000).floor();
12
12
final msecs = now.microsecondsSinceEpoch - secondsSinceEpoch * 1000000;
@@ -17,7 +17,7 @@ class ID {
17
17
// Generate a unique ID with padding to have a longer ID
18
18
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
19
19
static String unique({int padding = 7}) {
20
- String id = _uniqid ();
20
+ String id = _uniqueId ();
21
21
22
22
if (padding > 0) {
23
23
StringBuffer sb = StringBuffer();
Original file line number Diff line number Diff line change 1
1
export class ID {
2
- static uniqid(): string {
2
+ // Generate a unique ID based on timestamp
3
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
4
+ static #uniqueId(): string {
3
5
const now = new Date();
4
6
const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
5
7
const msecs = now.getTime() - secondsSinceEpoch * 1000;
@@ -14,8 +16,10 @@ export class ID {
14
16
return id
15
17
}
16
18
19
+ // Generate a unique ID with padding to have a longer ID
20
+ // Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
17
21
public static unique(padding: number = 7): string {
18
- const baseId = ID.uniqid ();
22
+ const baseId = ID.#uniqueId ();
19
23
let randomPadding = '';
20
24
21
25
for (let i = 0; i < padding; i++) {
Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ namespace {{ spec.title | caseUcfirst }}
4
4
{
5
5
public static class ID
6
6
{
7
- static string UniqID()
7
+ // Generate a unique ID based on timestamp
8
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
9
+ private static string uniqueId()
8
10
{
9
11
var now = DateTime.UtcNow;
10
12
var secondsSinceEpoch = (long)(now - new DateTime(1970, 1, 1)).TotalSeconds;
@@ -16,10 +18,12 @@ namespace {{ spec.title | caseUcfirst }}
16
18
return hexTimestamp;
17
19
}
18
20
21
+ // Generate a unique ID with padding to have a longer ID
22
+ // Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
19
23
public static string Unique(int padding = 7)
20
24
{
21
25
var random = new Random();
22
- var baseId = UniqID ();
26
+ var baseId = uniqueId ();
23
27
var randomPadding = "";
24
28
25
29
for (int i = 0; i < padding; i++)
Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ import java.time.Instant
4
4
import kotlin.math.floor
5
5
import kotlin.random.Random
6
6
7
- fun uniqid(): String {
7
+ // Generate a unique ID based on timestamp
8
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
9
+ private fun uniqueId(): String {
8
10
val currentTimestamp = Instant.now().toEpochMilli() / 1000.0
9
11
val secondsPart = floor(currentTimestamp).toLong()
10
12
val microsecondsPart = ((currentTimestamp - secondsPart) * 1_000_000).toLong()
@@ -18,8 +20,10 @@ class ID {
18
20
companion object {
19
21
fun custom(id: String): String
20
22
= id
23
+ // Generate a unique ID with padding to have a longer ID
24
+ // Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
21
25
fun unique(padding: Int = 7): String {
22
- val baseId = uniqid ()
26
+ val baseId = uniqueId ()
23
27
val randomPadding = (1..padding)
24
28
.map { Random.nextInt(0, 16).toString(16) }
25
29
.joinToString("")
Original file line number Diff line number Diff line change 1
1
class ID {
2
- static uniqid = () => {
2
+ // Generate a unique ID based on timestamp
3
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
4
+ static #uniqueId = () => {
3
5
const now = new Date();
4
6
const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
5
7
const msecs = now.getTime() - secondsSinceEpoch * 1000;
@@ -10,8 +12,10 @@ class ID {
10
12
return hexTimestamp;
11
13
}
12
14
15
+ // Generate a unique ID with padding to have a longer ID
16
+ // Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
13
17
static unique = (padding = 7) => {
14
- const baseId = ID.uniqid ();
18
+ const baseId = ID.#uniqueId ();
15
19
let randomPadding = '';
16
20
17
21
for (let i = 0; i < padding; i++) {
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ from datetime import datetime
2
2
import random
3
3
4
4
class ID:
5
+ // Generate a unique ID based on timestamp
6
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
5
7
@staticmethod
6
- def uniqid ():
8
+ def __uniqueId ():
7
9
now = datetime.now()
8
10
seconds_since_epoch = int(now.timestamp())
9
11
microseconds_part = now.microsecond
@@ -14,8 +16,10 @@ class ID:
14
16
def custom(id):
15
17
return id
16
18
19
+ // Generate a unique ID with padding to have a longer ID
20
+ // Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
17
21
@staticmethod
18
22
def unique(padding = 7):
19
- base_id = ID.uniqid ()
23
+ base_id = ID.__uniqueId ()
20
24
random_padding = ''.join(random.choice('0123456789abcdef') for _ in range(padding))
21
25
return base_id + random_padding
Original file line number Diff line number Diff line change 1
1
require 'securerandom'
2
2
3
- def uniqid
3
+ // Generate a unique ID based on timestamp
4
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
5
+ def uniqueId
4
6
now = Time.now
5
7
seconds_since_epoch = now.to_i
6
8
microseconds_part = now.usec
@@ -15,7 +17,7 @@ module {{spec.title | caseUcfirst}}
15
17
end
16
18
17
19
def self.unique(padding=7)
18
- base_id = uniqid
20
+ base_id = uniqueId
19
21
random_padding = SecureRandom.hex(padding)
20
22
random_padding = random_padding[0...padding]
21
23
base_id + random_padding
Original file line number Diff line number Diff line change 1
1
import Foundation
2
2
3
- func uniqid() -> String {
3
+ // Generate a unique ID based on timestamp
4
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
5
+ func uniqueId() -> String {
4
6
let now = Date()
5
7
let secondsSinceEpoch = Int(now.timeIntervalSince1970)
6
8
let microsecondsPart = Int((now.timeIntervalSince1970 - Double(secondsSinceEpoch)) * 1_000_000)
@@ -13,9 +15,13 @@ public class ID {
13
15
return id
14
16
}
15
17
18
+ // Generate a unique ID with padding to have a longer ID
19
+ // Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
16
20
public static func unique(padding: Int = 7) -> String {
17
- let baseId = uniqid()
18
- let randomPadding = (1...padding).map { _ in String(format: "%x", Int.random(in: 0..<16 )) }.joined ()
21
+ let baseId = uniqueId()
22
+ let randomPadding = (1...padding).map {
23
+ String(format: "%x", Int.random(in: 0..<16 ))
24
+ }.joined ()
19
25
return baseId + randomPadding
20
26
}
21
27
}
Original file line number Diff line number Diff line change 1
- function uniqid(): string {
1
+ // Generate a unique ID based on timestamp
2
+ // Recreated from https://www.php.net/manual/en/function.uniqid.php
3
+ function uniqueId(): string {
2
4
const now = new Date();
3
- const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
5
+ const secondsSinceEpoch = Math.floor(now.getTime() / 1000); // Get Unix Timestamp
4
6
const microsecondsPart = now.getMilliseconds() * 1000; // Convert milliseconds to microseconds
5
7
const hexTimestamp = `${secondsSinceEpoch.toString(16)}${microsecondsPart.toString(16).padStart(5, '0')}`;
6
8
return hexTimestamp;
@@ -12,7 +14,9 @@ export class ID {
12
14
}
13
15
14
16
public static unique(padding: number = 7): string {
15
- const baseId = uniqid();
17
+ // Generate a unique ID with padding to have a longer ID
18
+ // Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
19
+ const baseId = uniqueId();
16
20
let randomPadding = '';
17
21
for (let i = 0; i < padding; i++) {
18
22
const randomHexDigit = Math.floor(Math.random() * 16).toString(16);
You can’t perform that action at this time.
0 commit comments