Skip to content

Commit b2e069a

Browse files
Merge branch 'master' into dart-fl-upgrade-dependencies
2 parents 7956acc + 4aaa603 commit b2e069a

38 files changed

+1373
-814
lines changed

composer.lock

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SDK/Language/CLI.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Appwrite\SDK\Language;
44

5+
use Twig\TwigFilter;
56
use Twig\TwigFunction;
67

78
class CLI extends Node
@@ -364,6 +365,14 @@ public function getParamExample(array $param): string
364365
return $output;
365366
}
366367

368+
public function getFilters(): array
369+
{
370+
return array_merge(parent::getFilters(), [
371+
new TwigFilter('caseKebab', function ($value) {
372+
return strtolower(preg_replace('/(?<!^)([A-Z][a-z]|(?<=[a-z])[^a-z]|(?<=[A-Z])[0-9_])/', '-$1', $value));
373+
})
374+
]);
375+
}
367376
/**
368377
* Language specific filters.
369378
* @return array

src/SDK/Language/Go.php

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ public function getFiles(): array
6363
'destination' => 'go.mod',
6464
'template' => 'go/go.mod.twig',
6565
],
66-
[
67-
'scope' => 'default',
68-
'destination' => 'example/main.go',
69-
'template' => 'go/main.go.twig',
70-
],
7166
[
7267
'scope' => 'default',
7368
'destination' => 'README.md',
@@ -83,6 +78,11 @@ public function getFiles(): array
8378
'destination' => 'LICENSE',
8479
'template' => 'go/LICENSE.twig',
8580
],
81+
[
82+
'scope' => 'default',
83+
'destination' => 'appwrite/appwrite.go',
84+
'template' => 'go/appwrite.go.twig',
85+
],
8686
[
8787
'scope' => 'default',
8888
'destination' => 'client/client.go',
@@ -145,7 +145,9 @@ public function getTypeName(array $parameter, array $spec = []): string
145145
self::TYPE_STRING => 'string',
146146
self::TYPE_BOOLEAN => 'bool',
147147
self::TYPE_OBJECT => 'interface{}',
148-
self::TYPE_ARRAY => '[]interface{}',
148+
self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type']))
149+
? '[]' . $this->getTypeName($parameter['array'])
150+
: '[]string',
149151
default => $parameter['type'],
150152
};
151153
}
@@ -170,8 +172,10 @@ public function getParamDefault(array $param): string
170172
switch ($type) {
171173
case self::TYPE_NUMBER:
172174
case self::TYPE_INTEGER:
175+
$output .= "0";
176+
break;
173177
case self::TYPE_BOOLEAN:
174-
$output .= 'null';
178+
$output .= 'false';
175179
break;
176180
case self::TYPE_STRING:
177181
$output .= '""';
@@ -283,25 +287,34 @@ public function getFilters(): array
283287
}
284288
return implode("\n" . $indent, $value);
285289
}, ['is_safe' => ['html']]),
286-
new TwigFilter('propertyType', function (array $property, array $spec, string $generic = 'interface{}') {
290+
new TwigFilter('propertyType', function (array $property, array $spec, string $generic = 'map[string]interface{}') {
287291
return $this->getPropertyType($property, $spec, $generic);
288292
}),
289-
new TwigFilter('returnType', function (array $method, array $spec, string $namespace, string $generic = 'T') {
293+
new TwigFilter('returnType', function (array $method, array $spec, string $namespace, string $generic = 'map[string]interface{}') {
290294
return $this->getReturnType($method, $spec, $namespace, $generic);
291295
}),
292296
new TwigFilter('caseEnumKey', function (string $value) {
293297
return $this->toUpperSnakeCase($value);
294-
})
298+
}),
295299
];
296300
}
297301

298-
protected function getPropertyType(array $property, array $spec, string $generic = 'interface{}'): string
302+
protected function getPropertyType(array $property, array $spec, string $generic = 'map[string]interface{}'): string
299303
{
300-
$type = $this->getTypeName($property);
304+
if (\array_key_exists('sub_schema', $property)) {
305+
$type = $this->toPascalCase($property['sub_schema']);
306+
307+
if ($property['type'] === 'array') {
308+
$type = '[]' . $type;
309+
}
310+
} else {
311+
$type = $this->getTypeName($property);
312+
}
313+
301314
return $type;
302315
}
303316

304-
protected function getReturnType(array $method, array $spec, string $namespace, string $generic = 'T'): string
317+
protected function getReturnType(array $method, array $spec, string $namespace, string $generic = 'map[string]interface{}'): string
305318
{
306319
if ($method['type'] === 'webAuth') {
307320
return 'bool';
@@ -322,4 +335,27 @@ protected function getReturnType(array $method, array $spec, string $namespace,
322335

323336
return 'models.' . $ret;
324337
}
338+
339+
protected function hasGenericType(?string $model, array $spec): string
340+
{
341+
if (empty($model) || $model === 'any') {
342+
return false;
343+
}
344+
345+
$model = $spec['definitions'][$model];
346+
347+
if ($model['additionalProperties']) {
348+
return true;
349+
}
350+
351+
foreach ($model['properties'] as $property) {
352+
if (!\array_key_exists('sub_schema', $property) || !$property['sub_schema']) {
353+
continue;
354+
}
355+
356+
return $this->hasGenericType($property['sub_schema'], $spec);
357+
}
358+
359+
return false;
360+
}
325361
}

templates/cli/base/requests/api.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
);
2525
} else {
2626
parse(response)
27-
success()
2827
}
2928
{%~ else %}
3029
parse(response)
31-
success()
3230
{%~ endif %}
3331
}
3432

templates/cli/base/requests/file.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107

108108
if (parseOutput) {
109109
parse(response)
110-
success()
111110
}
112111

113112
return response;

templates/cli/index.js.twig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { login, logout, whoami, migrate, register } = require("./lib/commands/gen
1616
const { init } = require("./lib/commands/init");
1717
const { pull } = require("./lib/commands/pull");
1818
const { run } = require("./lib/commands/run");
19-
const { push } = require("./lib/commands/push");
19+
const { push, deploy } = require("./lib/commands/push");
2020
{% else %}
2121
const { migrate } = require("./lib/commands/generic");
2222
{% endif %}
@@ -30,15 +30,16 @@ program
3030
.description(commandDescriptions['main'])
3131
.configureHelp({
3232
helpWidth: process.stdout.columns || 80,
33-
sortSubcommands: true
33+
sortSubcommands: true,
3434
})
35-
.version(version, "-v, --version")
35+
.helpOption('-h, --help', "Display help for command")
36+
.version(version, "-v, --version", "Output the version number")
3637
.option("-V, --verbose", "Show complete error log")
3738
.option("-j, --json", "Output in JSON format")
3839
.hook('preAction', migrate)
3940
.option("-f,--force", "Flag to confirm all warnings")
4041
.option("-a,--all", "Flag to push all resources")
41-
.option("--id [id...]", "Flag to pass list of ids for a giving action")
42+
.option("--id [id...]", "Flag to pass a list of ids for a given action")
4243
.option("--report", "Enable reporting in case of CLI errors")
4344
.on("option:json", () => {
4445
cliConfig.json = true;
@@ -67,6 +68,7 @@ program
6768
.addCommand(init)
6869
.addCommand(pull)
6970
.addCommand(push)
71+
.addCommand(deploy)
7072
.addCommand(run)
7173
.addCommand(logout)
7274
{% endif %}

0 commit comments

Comments
 (0)