Skip to content

Commit 6821408

Browse files
committed
Merge branch 'master' into fix-js-bigint
2 parents c682069 + 1224ecb commit 6821408

File tree

45 files changed

+1139
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1139
-375
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
.env
99
.envrc
1010
.hatch
11+
1112
# exclude everything
1213
examples/*
14+
tests/tmp
15+
.phpunit.result.cache
1316

1417
# exception to the rule
15-
!examples/.gitkeep
18+
!examples/.gitkeep
19+
1620
**/.DS_Store
1721
templates/swift/example/.build
1822
templates/swift/example/Example.xcodeproj/project.xcworkspace/xcuserdata
1923
templates/swift/example/Example.xcodeproj/xcuserdata
2024
**/xcuserdata
25+
# exclude go checksum files
26+
go.sum

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ env:
2525
- SDK=DartStable
2626
- SDK=Deno1171
2727
- SDK=FlutterStable
28+
- SDK=Go112
29+
- SDK=Go118
2830
- SDK=FlutterBeta
2931
- SDK=KotlinJava8
3032
- SDK=KotlinJava11
33+
- SDK=KotlinJava17
3134
- SDK=Node12
3235
- SDK=Node14
3336
- SDK=Node16

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ $sdk->generate(__DIR__ . '/examples/php'); // Generate source code
100100
| Ruby | 2.4+ | [Ruby Style Guide] | GEM | [@eldadfux] [@abnegate] |
101101
| Python | 3.5+ | [PEP8] | PIP | [@eldadfux] [@abnegate] |
102102
| Dart | 2.7+ | [Effective Dart] | pub | [@lohanidamodar] |
103-
| Go | | [Effective Go] | go get | [@panz3r] |
103+
| Go | | [Effective Go] | go get | [@panz3r] [@phaus] |
104104
| .NET | .NET core 3.1 | [C# Coding Conventions]| NuGet | [@komemi] [@TorstenDittmann] |
105105
| D | | | ? | [You?](https://github.com/appwrite/sdk-generator/issues/20) |
106106
| Kotlin | 1.4.31+ | [Kotlin style guide] | Gradle, Maven | [@abnegate] |

example.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function getSSLPage($url) {
169169

170170
$sdk
171171
->setName('NAME')
172-
->setVersion('0.0.19')
172+
->setVersion('0.16.0')
173173
->setDescription('Repo description goes here')
174174
->setShortDescription('Repo short description goes here')
175175
->setURL('https://appwrite.io')
@@ -183,7 +183,7 @@ function getSSLPage($url) {
183183
->setTwitter('appwrite_io')
184184
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
185185
->setDefaultHeaders([
186-
'X-Appwrite-Response-Format' => '0.12.0',
186+
'X-Appwrite-Response-Format' => '0.13.0',
187187
])
188188
;
189189

@@ -299,8 +299,9 @@ function getSSLPage($url) {
299299
->setDescription('Repo description goes here')
300300
->setShortDescription('Repo short description goes here')
301301
->setURL('https://example.com')
302+
->setVersion('0.0.1')
302303
->setGitUserName('appwrite')
303-
->setGitRepoName('go-sdk')
304+
->setGitRepoName('sdk-for-go')
304305
->setLogo('https://appwrite.io/v1/images/console.png')
305306
->setLicenseContent('test test test')
306307
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')

src/SDK/Language/Go.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ public function getFiles()
5959
return [
6060
[
6161
'scope' => 'default',
62-
'destination' => 'main.go',
62+
'destination' => 'go.mod',
63+
'template' => 'go/go.mod.twig',
64+
'minify' => false,
65+
],
66+
[
67+
'scope' => 'default',
68+
'destination' => 'example/main.go',
6369
'template' => 'go/main.go.twig',
6470
'minify' => false,
6571
],
@@ -83,19 +89,13 @@ public function getFiles()
8389
],
8490
[
8591
'scope' => 'default',
86-
'destination' => 'client.go',
92+
'destination' => '{{ spec.title | caseLower}}/client.go',
8793
'template' => 'go/client.go.twig',
8894
'minify' => false,
8995
],
90-
[
91-
'scope' => 'default',
92-
'destination' => 'utils.go',
93-
'template' => 'go/utils.go.twig',
94-
'minify' => false,
95-
],
9696
[
9797
'scope' => 'service',
98-
'destination' => '{{service.name | caseDash}}.go',
98+
'destination' => '{{ spec.title | caseLower}}/{{service.name | caseDash}}.go',
9999
'template' => 'go/services/service.go.twig',
100100
'minify' => false,
101101
],
@@ -117,19 +117,18 @@ public function getTypeName($type)
117117
switch ($type) {
118118
case self::TYPE_INTEGER:
119119
return 'int';
120-
break;
120+
case self::TYPE_NUMBER:
121+
return 'float64';
121122
case self::TYPE_STRING:
122123
return 'string';
123-
break;
124124
case self::TYPE_FILE:
125125
return 'string'; // '*os.File';
126-
break;
127126
case self::TYPE_BOOLEAN:
128127
return 'bool';
129-
break;
128+
case self::TYPE_OBJECT:
129+
return 'interface{}';
130130
case self::TYPE_ARRAY:
131-
return '[]interface{}';
132-
break;
131+
return '[]interface{}';
133132
}
134133

135134
return $type;
@@ -161,6 +160,9 @@ public function getParamDefault(array $param)
161160
case self::TYPE_STRING:
162161
$output .= '""';
163162
break;
163+
case self::TYPE_OBJECT:
164+
$output .= 'nil';
165+
break;
164166
case self::TYPE_ARRAY:
165167
$output .= '[]';
166168
break;
@@ -173,11 +175,14 @@ public function getParamDefault(array $param)
173175
case self::TYPE_ARRAY:
174176
$output .= $default;
175177
break;
178+
case self::TYPE_OBJECT:
179+
$output .= "\"$default\"";
180+
break;
176181
case self::TYPE_BOOLEAN:
177182
$output .= ($default) ? 'true' : 'false';
178183
break;
179184
case self::TYPE_STRING:
180-
$output .= "\"{$default}\"";
185+
$output .= "nil";
181186
break;
182187
}
183188
}
@@ -206,6 +211,9 @@ public function getParamExample(array $param)
206211
case self::TYPE_STRING:
207212
$output .= '""';
208213
break;
214+
case self::TYPE_OBJECT:
215+
$output .= 'nil';
216+
break;
209217
case self::TYPE_ARRAY:
210218
$output .= '[]';
211219
break;
@@ -221,6 +229,9 @@ public function getParamExample(array $param)
221229
case self::TYPE_ARRAY:
222230
$output .= $example;
223231
break;
232+
case self::TYPE_OBJECT:
233+
$output .= 'nil';
234+
break;
224235
case self::TYPE_BOOLEAN:
225236
$output .= ($example) ? 'true' : 'false';
226237
break;

src/SDK/SDK.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,11 @@ protected function render(TemplateWrapper $template, $destination, $block, $para
741741
* @param string $str
742742
* @return string
743743
*/
744-
protected function helperCamelCase($str)
744+
protected function helperCamelCase($str): string
745745
{
746+
if ($str == null) {
747+
return '';
748+
}
746749
$str = preg_replace('/[^a-z0-9' . implode("", []) . ']+/i', ' ', $str);
747750
$str = trim($str);
748751
$str = ucwords($str);

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

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import okhttp3.RequestBody.Companion.toRequestBody
2323
import java.io.BufferedInputStream
2424
import java.io.BufferedReader
2525
import java.io.File
26+
import java.io.RandomAccessFile
2627
import java.io.IOException
2728
import java.net.CookieManager
2829
import java.net.CookiePolicy
@@ -225,7 +226,7 @@ class Client @JvmOverloads constructor(
225226
headers: Map<String, String> = mapOf(),
226227
params: Map<String, Any?> = mapOf(),
227228
responseType: Class<T>,
228-
convert: ((Map<String, Any,>) -> T)? = null
229+
converter: ((Map<String, Any,>) -> T)? = null
229230
): T {
230231
val filteredParams = params.filterValues { it != null }
231232

@@ -261,7 +262,7 @@ class Client @JvmOverloads constructor(
261262
.get()
262263
.build()
263264

264-
return awaitResponse(request, responseType, convert)
265+
return awaitResponse(request, responseType, converter)
265266
}
266267

267268
val body = if (MultipartBody.FORM.toString() == headers["content-type"]) {
@@ -298,7 +299,7 @@ class Client @JvmOverloads constructor(
298299
.method(method, body)
299300
.build()
300301

301-
return awaitResponse(request, responseType, convert)
302+
return awaitResponse(request, responseType, converter)
302303
}
303304

304305
/**
@@ -316,8 +317,9 @@ class Client @JvmOverloads constructor(
316317
headers: MutableMap<String, String>,
317318
params: MutableMap<String, Any?>,
318319
responseType: Class<T>,
319-
convert: ((Map<String, Any,>) -> T),
320+
converter: ((Map<String, Any,>) -> T),
320321
paramName: String,
322+
idParamName: String? = null,
321323
onProgress: ((UploadProgress) -> Unit)? = null,
322324
): T {
323325
val file = params[paramName] as File
@@ -330,74 +332,84 @@ class Client @JvmOverloads constructor(
330332
file.asRequestBody()
331333
)
332334
return call(
333-
"POST",
335+
method = "POST",
334336
path,
335337
headers,
336338
params,
337339
responseType,
338-
convert
340+
converter
339341
)
340342
}
341343

342-
val input = file.inputStream().buffered()
344+
val input = RandomAccessFile(file, "r")
343345
val buffer = ByteArray(CHUNK_SIZE)
344346
var offset = 0L
345347
var result: Map<*, *>? = null
346348

347-
generateSequence {
348-
val readBytes = input.read(buffer)
349-
if (readBytes >= 0) {
350-
buffer.copyOf(readBytes)
351-
} else {
352-
input.close()
353-
null
354-
}
355-
}.forEach {
349+
if (idParamName?.isNotEmpty() == true && params[idParamName] != "unique()") {
350+
// Make a request to check if a file already exists
351+
val current = call(
352+
method = "GET",
353+
path = "$path/${params[idParamName]}",
354+
headers = headers,
355+
params = emptyMap(),
356+
responseType = Map::class.java,
357+
)
358+
val chunksUploaded = current["chunksUploaded"] as Long
359+
offset = (chunksUploaded * CHUNK_SIZE).coerceAtMost(size)
360+
}
361+
362+
while (offset < size) {
363+
input.seek(offset)
364+
input.read(buffer)
365+
356366
params[paramName] = MultipartBody.Part.createFormData(
357367
paramName,
358368
file.name,
359-
it.toRequestBody()
369+
buffer.toRequestBody()
360370
)
361371

362372
headers["Content-Range"] =
363373
"bytes $offset-${((offset + CHUNK_SIZE) - 1).coerceAtMost(size)}/$size"
364374

365375
result = call(
366-
"POST",
376+
method = "POST",
367377
path,
368378
headers,
369379
params,
370-
Map::class.java
380+
responseType = Map::class.java
371381
)
372382

373383
offset += CHUNK_SIZE
374384
headers["x-{{ spec.title | caseLower }}-id"] = result!!["\$id"].toString()
375-
onProgress?.invoke(UploadProgress(
376-
id = result!!["\$id"].toString(),
377-
progress = offset.coerceAtMost(size).toDouble()/size * 100,
378-
sizeUploaded = offset.coerceAtMost(size),
379-
chunksTotal = result!!["chunksTotal"].toString().toInt(),
380-
chunksUploaded = result!!["chunksUploaded"].toString().toInt(),
381-
))
385+
onProgress?.invoke(
386+
UploadProgress(
387+
id = result!!["\$id"].toString(),
388+
progress = offset.coerceAtMost(size).toDouble() / size * 100,
389+
sizeUploaded = offset.coerceAtMost(size),
390+
chunksTotal = result!!["chunksTotal"].toString().toInt(),
391+
chunksUploaded = result!!["chunksUploaded"].toString().toInt(),
392+
)
393+
)
382394
}
383395

384-
return convert(result as Map<String, Any>)
396+
return converter(result as Map<String, Any>)
385397
}
386398

387399
/**
388400
* Await Response
389401
*
390402
* @param request
391403
* @param responseType
392-
* @param convert
404+
* @param converter
393405
*
394406
* @return [T]
395407
*/
396408
@Throws({{ spec.title | caseUcfirst }}Exception::class)
397409
private suspend fun <T> awaitResponse(
398410
request: Request,
399411
responseType: Class<T>,
400-
convert: ((Map<String, Any,>) -> T)? = null
412+
converter: ((Map<String, Any,>) -> T)? = null
401413
) = suspendCancellableCoroutine<T> {
402414
http.newCall(request).enqueue(object : Callback {
403415
override fun onFailure(call: Call, e: IOException) {
@@ -463,7 +475,7 @@ class Client @JvmOverloads constructor(
463475
object : TypeToken<Map<String, Any>>(){}.type
464476
)
465477
it.resume(
466-
convert?.invoke(map) ?: map as T
478+
converter?.invoke(map) ?: map as T
467479
)
468480
}
469481
})

0 commit comments

Comments
 (0)