Skip to content

Commit 8ff9c98

Browse files
Continue work on moving ID Generation to clients
1 parent 440d350 commit 8ff9c98

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

templates/deno/src/id.ts.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export class ID {
2-
function uniqid(): string {
2+
static uniqid(): string {
33
const now = new Date();
44
const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
55
const msecs = now.getTime() - secondsSinceEpoch * 1000;
@@ -15,7 +15,7 @@ export class ID {
1515
}
1616

1717
public static unique(padding: number = 5): string {
18-
const baseId = uniqid();
18+
const baseId = ID.uniqid();
1919
let randomPadding = '';
2020

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace {{ spec.title | caseUcfirst }}
24
{
35
public static class ID
@@ -16,6 +18,7 @@ namespace {{ spec.title | caseUcfirst }}
1618

1719
public static string Unique(int padding = 5)
1820
{
21+
var random = new Random();
1922
var baseId = UniqID();
2023
var randomPadding = "";
2124

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-
static function uniqid() {
2+
static uniqid = () => {
33
const now = new Date();
44
const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
55
const msecs = now.getTime() - secondsSinceEpoch * 1000;
@@ -11,7 +11,7 @@ class ID {
1111
}
1212

1313
static unique = (padding = 7) => {
14-
const baseId = uniqid();
14+
const baseId = ID.uniqid();
1515
let randomPadding = '';
1616

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

templates/python/package/id.py.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class ID:
1616

1717
@staticmethod
1818
def unique(padding = 5):
19-
base_id = uniqid()
19+
base_id = uniqid()
2020
random_padding = ''.join(random.choice('0123456789abcdef') for _ in range(padding))
2121
return base_id + random_padding

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module {{spec.title | caseUcfirst}}
1414
id
1515
end
1616

17-
def self.unique_id(padding=5)
17+
def self.unique(padding=5)
1818
base_id = uniqid
1919
random_padding = SecureRandom.hex(padding / 2)
2020
random_padding = random_padding[0...padding]

tests/Base.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,14 @@ public function testHTTPSuccess(): void
212212
$this->assertGreaterThanOrEqual(count($this->expectedOutput), count($output));
213213

214214
foreach ($this->expectedOutput as $i => $row) {
215-
$this->assertEquals($output[$i], $row);
215+
// Check we are generating ID's correctly
216+
if ($row == 'unique()') {
217+
$this->assertNotEmpty($output[$i]);
218+
$this->assertIsString($output[$i]);
219+
$this->assertNotEquals($output[$i], 'unique()');
220+
} else {
221+
$this->assertEquals($output[$i], $row);
222+
}
216223
}
217224
}
218225

0 commit comments

Comments
 (0)