Skip to content

Commit 0ebec26

Browse files
Address comments
1 parent 280db65 commit 0ebec26

File tree

10 files changed

+29
-29
lines changed

10 files changed

+29
-29
lines changed

templates/android/library/src/main/java/io/appwrite/ID.kt.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import java.time.Instant
44
import kotlin.math.floor
55
import kotlin.random.Random
66

7-
// Generate a unique ID based on timestamp
7+
// Generate an hex ID based on timestamp
88
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9-
private fun uniqueId(): String {
9+
private fun hexTimestamp(): String {
1010
val currentTimestamp = Instant.now().toEpochMilli() / 1000.0
1111
val secondsPart = floor(currentTimestamp).toLong()
1212
val microsecondsPart = ((currentTimestamp - secondsPart) * 1_000_000).toLong()
@@ -24,7 +24,7 @@ class ID {
2424
// Generate a unique ID with padding to have a longer ID
2525
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
2626
fun unique(padding: Int = 7): String {
27-
val baseId = uniqueId()
27+
val baseId = hexTimestamp()
2828
val randomPadding = (1..padding)
2929
.map { Random.nextInt(0, 16).toString(16) }
3030
.joinToString("")

templates/dart/lib/id.dart.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ part of {{ language.params.packageName }};
44
class ID {
55
ID._();
66

7-
// Generate a unique ID based on timestamp
7+
// Generate an hex ID based on timestamp
88
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9-
static String _uniqueId() {
9+
static String _hexTimestamp() {
1010
final now = DateTime.now();
1111
final secondsSinceEpoch = (now.millisecondsSinceEpoch / 1000).floor();
1212
final msecs = now.microsecondsSinceEpoch - secondsSinceEpoch * 1000000;
@@ -17,7 +17,7 @@ class ID {
1717
// Generate a unique ID with padding to have a longer ID
1818
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
1919
static String unique({int padding = 7}) {
20-
String id = _uniqueId();
20+
String id = _hexTimestamp();
2121

2222
if (padding > 0) {
2323
StringBuffer sb = StringBuffer();

templates/deno/src/id.ts.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class ID {
2-
// Generate a unique ID based on timestamp
2+
// Generate an hex ID based on timestamp
33
// Recreated from https://www.php.net/manual/en/function.uniqid.php
4-
static #uniqueId(): string {
4+
static #hexTimestamp(): string {
55
const now = new Date();
66
const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
77
const msecs = now.getTime() - secondsSinceEpoch * 1000;
@@ -19,7 +19,7 @@ export class ID {
1919
// Generate a unique ID with padding to have a longer ID
2020
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
2121
public static unique(padding: number = 7): string {
22-
const baseId = ID.#uniqueId();
22+
const baseId = ID.#hexTimestamp();
2323
let randomPadding = '';
2424

2525
for (let i = 0; i < padding; i++) {

templates/dotnet/src/Appwrite/ID.cs.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace {{ spec.title | caseUcfirst }}
44
{
55
public static class ID
66
{
7-
// Generate a unique ID based on timestamp
7+
// Generate an hex ID based on timestamp
88
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9-
private static string uniqueId()
9+
private static string hexTimestamp()
1010
{
1111
var now = DateTime.UtcNow;
1212
var secondsSinceEpoch = (long)(now - new DateTime(1970, 1, 1)).TotalSeconds;
@@ -23,7 +23,7 @@ namespace {{ spec.title | caseUcfirst }}
2323
public static string Unique(int padding = 7)
2424
{
2525
var random = new Random();
26-
var baseId = uniqueId();
26+
var baseId = hexTimestamp();
2727
var randomPadding = "";
2828

2929
for (int i = 0; i < padding; i++)

templates/kotlin/src/main/kotlin/io/appwrite/ID.kt.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import java.time.Instant
44
import kotlin.math.floor
55
import kotlin.random.Random
66

7-
// Generate a unique ID based on timestamp
7+
// Generate an hex ID based on timestamp
88
// Recreated from https://www.php.net/manual/en/function.uniqid.php
9-
private fun uniqueId(): String {
9+
private fun hexTimestamp(): String {
1010
val currentTimestamp = Instant.now().toEpochMilli() / 1000.0
1111
val secondsPart = floor(currentTimestamp).toLong()
1212
val microsecondsPart = ((currentTimestamp - secondsPart) * 1_000_000).toLong()
@@ -23,7 +23,7 @@ class ID {
2323
// Generate a unique ID with padding to have a longer ID
2424
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
2525
fun unique(padding: Int = 7): String {
26-
val baseId = uniqueId()
26+
val baseId = hexTimestamp()
2727
val randomPadding = (1..padding)
2828
.map { Random.nextInt(0, 16).toString(16) }
2929
.joinToString("")

templates/node/lib/id.js.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class ID {
2-
// Generate a unique ID based on timestamp
2+
// Generate an hex ID based on timestamp
33
// Recreated from https://www.php.net/manual/en/function.uniqid.php
44
static #uniqueId = () => {
55
const now = new Date();
@@ -15,7 +15,7 @@ class ID {
1515
// Generate a unique ID with padding to have a longer ID
1616
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
1717
static unique = (padding = 7) => {
18-
const baseId = ID.#uniqueId();
18+
const baseId = ID.#hexTimestamp();
1919
let randomPadding = '';
2020

2121
for (let i = 0; i < padding; i++) {

templates/python/package/id.py.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ from datetime import datetime
22
import random
33

44
class ID:
5-
# Generate a unique ID based on timestamp
5+
# Generate an hex ID based on timestamp
66
# Recreated from https://www.php.net/manual/en/function.uniqid.php
77
@staticmethod
8-
def __uniqueId():
8+
def __hex_timestamp():
99
now = datetime.now()
1010
seconds_since_epoch = int(now.timestamp())
1111
microseconds_part = now.microsecond
@@ -20,6 +20,6 @@ class ID:
2020
# Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
2121
@staticmethod
2222
def unique(padding = 7):
23-
base_id = ID.__uniqueId()
23+
base_id = ID.__hex_timestamp()
2424
random_padding = ''.join(random.choice('0123456789abcdef') for _ in range(padding))
2525
return base_id + random_padding

templates/ruby/lib/container/id.rb.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require 'securerandom'
22

3-
#Generate a unique ID based on timestamp
3+
#Generate an hex ID based on timestamp
44
#Recreated from https://www.php.net/manual/en/function.uniqid.php
5-
def uniqueId
5+
def hex_timestamp
66
now = Time.now
77
seconds_since_epoch = now.to_i
88
microseconds_part = now.usec
@@ -19,7 +19,7 @@ module {{spec.title | caseUcfirst}}
1919
# Generate a unique ID with padding to have a longer ID
2020
# Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
2121
def self.unique(padding=7)
22-
base_id = uniqueId
22+
base_id = hex_timestamp
2323
random_padding = SecureRandom.hex(padding)
2424
random_padding = random_padding[0...padding]
2525
base_id + random_padding

templates/swift/Sources/ID.swift.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
22

3-
// Generate a unique ID based on timestamp
3+
// Generate an hex ID based on timestamp
44
// Recreated from https://www.php.net/manual/en/function.uniqid.php
5-
func uniqueId() -> String {
5+
func hexTimestamp() -> String {
66
let now = Date()
77
let secondsSinceEpoch = Int(now.timeIntervalSince1970)
88
let microsecondsPart = Int((now.timeIntervalSince1970 - Double(secondsSinceEpoch)) * 1_000_000)
@@ -18,7 +18,7 @@ public class ID {
1818
// Generate a unique ID with padding to have a longer ID
1919
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
2020
public static func unique(padding: Int = 7) -> String {
21-
let baseId = uniqueId()
21+
let baseId = hexTimestamp()
2222
let randomPadding = (1...padding).map {
2323
_ in String(format: "%x", Int.random(in: 0..<16))
2424
}.joined()

templates/web/src/id.ts.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Generate a unique ID based on timestamp
1+
// Generate an hex ID based on timestamp
22
// Recreated from https://www.php.net/manual/en/function.uniqid.php
3-
function uniqueId(): string {
3+
function hexTimestamp(): string {
44
const now = new Date();
55
const secondsSinceEpoch = Math.floor(now.getTime() / 1000); // Get Unix Timestamp
66
const microsecondsPart = now.getMilliseconds() * 1000; // Convert milliseconds to microseconds
@@ -16,7 +16,7 @@ export class ID {
1616
public static unique(padding: number = 7): string {
1717
// Generate a unique ID with padding to have a longer ID
1818
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
19-
const baseId = uniqueId();
19+
const baseId = hexTimestamp();
2020
let randomPadding = '';
2121
for (let i = 0; i < padding; i++) {
2222
const randomHexDigit = Math.floor(Math.random() * 16).toString(16);

0 commit comments

Comments
 (0)