Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust SDK #436

Open
wants to merge 85 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
92e5406
Start work on client
PineappleIOnic Mar 8, 2021
1fa69ba
Add formdata and json to call() on client
PineappleIOnic Mar 8, 2021
96ae155
Create basic twig templates
PineappleIOnic Mar 10, 2021
c9048f6
Fix accidental NodeJS Template Change
PineappleIOnic Mar 14, 2021
50d4cb8
Finish Template
PineappleIOnic Mar 14, 2021
66169af
Add Readme and user-agent header
PineappleIOnic Mar 15, 2021
9f56d8b
Fix Licence Name in cargo.toml and Indentation in the twig templates
PineappleIOnic Mar 16, 2021
a43d7af
fix whitespace
TorstenDittmann Mar 16, 2021
070a10c
Remove Hardcoded Package Name
PineappleIOnic Mar 18, 2021
fbeeb7f
Merge branch 'rust-language-support' of https://github.com/PineappleI…
PineappleIOnic Mar 18, 2021
8d3bbba
Fix imports that were missed when changing to variable package name
PineappleIOnic Mar 18, 2021
07499a8
Make arrays easier to use by using borrowed arrays
PineappleIOnic Mar 18, 2021
28a3658
Add example generation
PineappleIOnic Mar 22, 2021
09aeab3
Merge branch 'master' into rust-language-support
PineappleIOnic Mar 22, 2021
c0bb109
Remove Java from SDKTests
PineappleIOnic Mar 22, 2021
447ba46
fix tests
PineappleIOnic Mar 22, 2021
918e4f1
First implementation of Exceptions
PineappleIOnic Mar 23, 2021
5d5f559
Add tests for exceptions
PineappleIOnic Mar 23, 2021
64a081b
Fix hardcoded exception
PineappleIOnic Mar 30, 2021
116d3d7
Only return underlying error when we fail to parse a Appwrite API Error
PineappleIOnic Mar 31, 2021
23e3f9e
Merge branch 'master' into rust-language-support
TorstenDittmann Apr 16, 2021
601dc43
Update test to add Test Started message
PineappleIOnic Apr 16, 2021
f346316
Update templates/rust/src/client.rs.twig
PineappleIOnic Apr 29, 2021
3cccccd
Add cookies feature on reqwest
PineappleIOnic Apr 29, 2021
a1f6745
Update templates/rust/src/services/service.rs.twig
PineappleIOnic Apr 29, 2021
434cb04
Add add_self_signed function to Client in SDK and Remove Cookies
PineappleIOnic May 4, 2021
d79ba01
Merge branch 'master' into rust-language-support
PineappleIOnic May 7, 2021
5fa73cd
Update SDKTest.php
PineappleIOnic May 11, 2021
8874c2a
Merge branch 'master' into rust-language-support
PineappleIOnic May 12, 2021
6d3d35f
Merge branch 'appwrite:master' into rust-language-support
PineappleIOnic Jun 1, 2021
45f2977
Add text error fallback
PineappleIOnic Jun 1, 2021
694311e
Merge branch 'master' into rust-language-support
PineappleIOnic Jun 7, 2021
b7fbda3
Merge branch 'appwrite:master' into rust-language-support
PineappleIOnic Jun 14, 2021
ebe5153
Merge branch 'master' into rust-language-support
PineappleIOnic Jun 21, 2021
dc6d216
Bring up to date with master
PineappleIOnic Jun 21, 2021
583a0da
Add Floats
PineappleIOnic Jun 23, 2021
b02485d
Implement Optional Parameters into Rust SDK
PineappleIOnic Jun 25, 2021
e11a6f9
Merge branch 'master' into rust-language-support
PineappleIOnic Jun 29, 2021
1ab01c9
Update service.rs.twig
PineappleIOnic Jun 29, 2021
eb42bbd
Merge branch 'master' into rust-language-support
PineappleIOnic Sep 23, 2021
ce4ca0c
Merge branch 'master' into rust-language-support
PineappleIOnic Sep 23, 2021
19bafd5
Implement Response Models
PineappleIOnic Sep 23, 2021
64a73b0
Implement Optional Parameters into Models
PineappleIOnic Sep 23, 2021
3bbc34d
Improve Serialisation
PineappleIOnic Sep 24, 2021
a926fed
Various Fixes See Desc
PineappleIOnic Oct 4, 2021
20a8d84
tests(rust): improvements
TorstenDittmann Oct 17, 2021
a1cfba2
revert whitelist
TorstenDittmann Oct 17, 2021
6815c8d
Merge pull request #4 from TorstenDittmann/rust-language-support-impr…
PineappleIOnic Oct 17, 2021
67c76fd
Merge branch 'rust-language-support' into rust-response-models
PineappleIOnic Oct 17, 2021
4eea144
Update SDKTest.php
PineappleIOnic Oct 17, 2021
abf62b5
Update Cargo.toml.twig
PineappleIOnic Oct 18, 2021
28276bf
Update rust.php
PineappleIOnic Oct 18, 2021
820ed3c
Fix tests for response models
PineappleIOnic Oct 18, 2021
65f5071
Merge branch 'master' into rust-language-support
PineappleIOnic Dec 6, 2021
61ffca8
Merge branch 'master' into rust-response-models
PineappleIOnic Jan 6, 2022
b362292
Fix Rust
PineappleIOnic Jan 6, 2022
332db26
Merge branch 'rust-language-support' into rust-response-models
PineappleIOnic Jan 6, 2022
9d20010
Rust Response Tests
PineappleIOnic Feb 8, 2022
e52bf31
Merge branch 'master' into rust-response-models
PineappleIOnic Feb 10, 2022
2d77837
Start adding attributes
PineappleIOnic Apr 27, 2022
02b8498
Merge remote-tracking branch 'upstream/master' into rust-response-models
PineappleIOnic Apr 27, 2022
c74856e
Get Rust SDK buildable again
PineappleIOnic Apr 27, 2022
f74a706
First Fully functional SDK Build for Rust
PineappleIOnic Apr 29, 2022
6622957
Delete buildRust.php
PineappleIOnic Apr 29, 2022
b2a4e36
Update example.php
PineappleIOnic Apr 29, 2022
7333378
Clean Up PR
PineappleIOnic Apr 29, 2022
87aa86b
Start working on implementing new test style
PineappleIOnic Apr 29, 2022
a6b2ee3
Update .travis.yml
PineappleIOnic Apr 29, 2022
7443a01
Update RustTest.php
PineappleIOnic Apr 29, 2022
dba364d
Continue working on tests
PineappleIOnic May 3, 2022
d822b93
Get Tests Passing
PineappleIOnic May 3, 2022
8e02f24
Merge remote-tracking branch 'upstream/master' into rust-response-models
PineappleIOnic May 3, 2022
3a9c624
Add beta and nightly tests
PineappleIOnic May 3, 2022
d609c72
Update docblocks and remove warnings
PineappleIOnic May 3, 2022
03fe8f1
Add Chunked Upload support
PineappleIOnic May 5, 2022
8fc982e
Update Tests for Large File Support
PineappleIOnic May 5, 2022
db57609
Update .travis.yml
PineappleIOnic May 5, 2022
64c0d6d
Fix nightly and beta installers for Rust
PineappleIOnic May 9, 2022
74f1e80
Re-add Attribute.rs
PineappleIOnic May 18, 2022
1ccbbb7
Update example template
PineappleIOnic May 18, 2022
773b0ea
Merge remote-tracking branch 'upstream/master' into rust-response-models
PineappleIOnic May 18, 2022
d185b15
Add publish workflow
PineappleIOnic May 18, 2022
0e4b976
Fix Github Action
PineappleIOnic May 18, 2022
a1938dc
Update Rust.php
PineappleIOnic Jun 6, 2022
b1286de
Merge remote-tracking branch 'upstream/master' into rust-response-models
PineappleIOnic Jul 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ env:
- SDK=SwiftServer55
- SDK=WebChromium
- SDK=WebNode
- SDK=Rust
- SDK=RustBeta
- SDK=RustNightly

notifications:
email:
Expand Down
26 changes: 26 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Appwrite\SDK\Language\Flutter;
use Appwrite\SDK\Language\Android;
use Appwrite\SDK\Language\Kotlin;
use Appwrite\SDK\Language\Rust;

try {

Expand Down Expand Up @@ -457,6 +458,31 @@ function getSSLPage($url) {
])
;
$sdk->generate(__DIR__ . '/examples/kotlin');

// Rust
$rust = new Rust();
$rust->setPackageName('appwrite');

$sdk = new SDK($rust, new Swagger2($spec));

$sdk
->setName('NAME')
->setDescription('Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Rust SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to https://appwrite.io/docs')
->setShortDescription('Appwrite Rust SDK')
->setURL('https://example.com')
->setLogo('https://appwrite.io/v1/images/console.png')
->setLicenseContent('test test test')
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')
->setChangelog('**CHANGELOG**')
->setVersion('0.0.1')
->setGitUserName('repoowner')
->setGitRepoName('reponame')
->setDefaultHeaders([
'X-Appwrite-Response-Format' => '0.7.0',
])
;

$sdk->generate(__DIR__ . '/examples/rust');
}
catch (Exception $exception) {
echo 'Error: ' . $exception->getMessage() . ' on ' . $exception->getFile() . ':' . $exception->getLine() . "\n";
Expand Down
299 changes: 299 additions & 0 deletions src/SDK/Language/Rust.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
<?php

namespace Appwrite\SDK\Language;

use Appwrite\SDK\Language;

class Rust extends Language
{
/**
* @var array
*/
protected $params = [
'packageName' => 'packageName',
];

/**
* @param string $name
* @return $this
*/
public function setPackageName($name)
{
$this->setParam('packageName', $name);

return $this;
}

/**
* @return string
*/
public function getName()
{
return 'Rust';
}

/**
* Get Language Keywords List
*
* @return array
*/
public function getKeywords()
{
return [
"type",
"as",
"break",
"const",
"continue",
"crate",
"else",
"enum",
"extern",
"false",
"fn",
"for",
"if",
"impl",
"in",
"let",
"loop",
"match",
"mod",
"move",
"mut",
"pub",
"ref",
"return",
"self",
"Self",
"static",
"struct",
"super",
"trait",
"true",
"type",
"unsafe",
"use",
"where",
"while",
"async",
"await",
"dyn",
"abstract",
"become",
"box",
"do",
"final",
"macro",
"override",
"priv",
"typeof",
"unsized",
"virtual",
"yield",
"try"
];
}

/**
* @return array
*/
public function getIdentifierOverrides()
{
return [];
}

/**
* @param $type
* @return string
*/
public function getTypeName($type)
{
switch ($type) {
case self::TYPE_OBJECT:
return 'Option<HashMap<String, crate::client::ParamType>>';
break;
case self::TYPE_INTEGER:
return 'i64';
break;
case self::TYPE_STRING:
return '&str';
break;
case self::TYPE_FILE:
return 'std::path::PathBuf';
break;
case self::TYPE_BOOLEAN:
return 'bool';
break;
case self::TYPE_ARRAY:
return '&[&str]';
case self::TYPE_NUMBER:
return 'f64';
break;
}

return $type;
}

/**
* @param array $param
* @return string
*/
public function getParamDefault(array $param)
{
return "";
}

/**
* @param array $param
* @return string
*/
public function getParamExample(array $param)
{
$type = $param['type'] ?? '';
$example = $param['example'] ?? '';

$output = '';

if (empty($example) && $example !== 0 && $example !== false) {
switch ($type) {
case self::TYPE_FILE:
$output .= 'std::path::PathBuf::from("./path-to-files/image.jpg")';
break;
case self::TYPE_NUMBER:
case self::TYPE_INTEGER:
$output .= '0';
break;
case self::TYPE_BOOLEAN:
$output .= 'false';
break;
case self::TYPE_STRING:
$output .= 'String::new()';
break;
case self::TYPE_OBJECT:
$output .= 'new Object()';
break;
case self::TYPE_ARRAY:
$output .= '&[]';
break;
}
} else {
switch ($type) {
case self::TYPE_OBJECT:
case self::TYPE_FILE:
case self::TYPE_NUMBER:
case self::TYPE_INTEGER:
case self::TYPE_ARRAY:
$output .= $example;
break;
case self::TYPE_BOOLEAN:
$output .= ($example) ? 'true' : 'false';
break;
case self::TYPE_STRING:
$output .= sprintf('"%s"', $example);
break;
}
}

return $output;
}

/**
* @return array
*/
public function getFiles()
{
return [
[
'scope' => 'default',
'destination' => 'Cargo.toml',
'template' => '/rust/Cargo.toml.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'README.md',
'template' => '/rust/README.md.twig',
'minify' => false,
],
[
'scope' => 'copy',
'destination' => '.github/workflows/cargo-publish.yml',
'template' => '/rust/.github/workflows/cargo-publish.yml',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'CHANGELOG.md',
'template' => '/rust/CHANGELOG.md.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => '.gitignore',
'template' => '/rust/.gitignore.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'LICENSE',
'template' => '/rust/LICENSE.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'src/models/attribute.rs',
'template' => '/rust/src/models/attribute.rs.twig',
'minify' => false,
],
[
'scope' => 'method',
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
'template' => '/rust/docs/example.md.twig',
'minify' => false,
],
[
'scope' => 'method',
'destination' => 'src/lib.rs',
'template' => '/rust/src/lib.rs.twig',
'minify' => false,
],
[
'scope' => 'method',
'destination' => 'src/client.rs',
'template' => '/rust/src/client.rs.twig',
'minify' => false,
],
[
'scope' => 'method',
'destination' => 'src/services/mod.rs',
'template' => '/rust/src/services/mod.rs.twig',
'minify' => false,
],
[
'scope' => 'method',
'destination' => 'src/services/exception.rs',
'template' => '/rust/src/services/exception.rs.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => 'src/models/mod.rs',
'template' => '/rust/src/models/mod.rs.twig',
'minify' => false,
],
[
'scope' => 'service',
'destination' => 'src/services/{{service.name | caseDash}}.rs',
'template' => '/rust/src/services/service.rs.twig',
'minify' => false,
],
[
'scope' => 'definition',
'destination' => '/src/models/{{definition.name | caseSnake }}.rs',
'template' => '/rust/src/models/model.rs.twig',
'minify' => false,
]
];
}
}
Loading