-
Notifications
You must be signed in to change notification settings - Fork 160
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
React native SDK #794
Merged
Merged
React native SDK #794
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ed28d86
react native templates
lohanidamodar 9f5760b
update readme
lohanidamodar e6a7421
github action to publish
lohanidamodar a2022ab
fix publish template
lohanidamodar 132ca5e
fixes and add origin
lohanidamodar bbbb5ce
use expo file system
lohanidamodar e25bf34
Merge remote-tracking branch 'origin/master' into feat-react-native-sdk
lohanidamodar c1affb9
fix file upload android
lohanidamodar 6ec8dca
update to use RN platform
lohanidamodar 8d1a997
fix review comments
lohanidamodar 4826075
adding timestamp
lohanidamodar b8a9e3e
publish RC rleases tagged as next
lohanidamodar bdfc605
fix build issues
lohanidamodar 8b0e5dc
fix check
lohanidamodar 59aa268
fix build issues
lohanidamodar db41717
return URI for oauth
lohanidamodar d679f9c
Update templates/react-native/src/client.ts.twig
lohanidamodar ea10075
Update templates/react-native/src/client.ts.twig
lohanidamodar dd6e9a4
Merge remote-tracking branch 'origin/master' into feat-react-native-sdk
lohanidamodar cf54f04
refactor exports
lohanidamodar 9a5e00d
fix escape special chars
lohanidamodar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
<?php | ||
|
||
namespace Appwrite\SDK\Language; | ||
|
||
use Twig\TwigFilter; | ||
|
||
class ReactNative extends Web | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'ReactNative'; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getFiles(): array | ||
{ | ||
return [ | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'src/index.ts', | ||
'template' => 'react-native/src/index.ts.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'src/client.ts', | ||
'template' => 'react-native/src/client.ts.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'src/service.ts', | ||
'template' => 'react-native/src/service.ts.twig', | ||
], | ||
[ | ||
'scope' => 'service', | ||
'destination' => 'src/services/{{service.name | caseDash}}.ts', | ||
'template' => 'react-native/src/services/template.ts.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'src/models.ts', | ||
'template' => 'react-native/src/models.ts.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'src/permission.ts', | ||
'template' => 'react-native/src/permission.ts.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'src/role.ts', | ||
'template' => 'react-native/src/role.ts.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'src/id.ts', | ||
'template' => 'react-native/src/id.ts.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'src/query.ts', | ||
'template' => 'react-native/src/query.ts.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'README.md', | ||
'template' => 'react-native/README.md.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'CHANGELOG.md', | ||
'template' => 'react-native/CHANGELOG.md.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'LICENSE', | ||
'template' => 'react-native/LICENSE.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'package.json', | ||
'template' => 'react-native/package.json.twig', | ||
], | ||
[ | ||
'scope' => 'method', | ||
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md', | ||
'template' => 'react-native/docs/example.md.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'tsconfig.json', | ||
'template' => '/react-native/tsconfig.json.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'rollup.config.js', | ||
'template' => '/react-native/rollup.config.js.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'dist/cjs/package.json', | ||
'template' => '/react-native/dist/cjs/package.json.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => 'dist/esm/package.json', | ||
'template' => '/react-native/dist/esm/package.json.twig', | ||
], | ||
[ | ||
'scope' => 'default', | ||
'destination' => '.github/workflows/publish.yml', | ||
'template' => 'react-native/.github/workflows/publish.yml.twig', | ||
], | ||
[ | ||
'scope' => 'enum', | ||
'destination' => 'src/enums/{{ enum.name | caseDash }}.ts', | ||
'template' => 'react-native/src/enums/enum.ts.twig', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param array $parameter | ||
* @param array $nestedTypes | ||
* @return string | ||
*/ | ||
public function getTypeName(array $parameter, array $spec = []): string | ||
{ | ||
if (isset($parameter['enumName'])) { | ||
return \ucfirst($parameter['enumName']); | ||
} | ||
if (!empty($parameter['enumValues'])) { | ||
return \ucfirst($parameter['name']); | ||
} | ||
switch ($parameter['type']) { | ||
case self::TYPE_INTEGER: | ||
case self::TYPE_NUMBER: | ||
return 'number'; | ||
case self::TYPE_ARRAY: | ||
if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) { | ||
return $this->getTypeName($parameter['array']) . '[]'; | ||
} | ||
return 'string[]'; | ||
case self::TYPE_FILE: | ||
return 'any'; | ||
} | ||
|
||
return $parameter['type']; | ||
} | ||
|
||
/** | ||
* @param array $param | ||
* @return string | ||
*/ | ||
public function getParamExample(array $param): string | ||
{ | ||
$type = $param['type'] ?? ''; | ||
$example = $param['example'] ?? ''; | ||
|
||
$output = ''; | ||
|
||
if (empty($example) && $example !== 0 && $example !== false) { | ||
switch ($type) { | ||
case self::TYPE_NUMBER: | ||
case self::TYPE_INTEGER: | ||
case self::TYPE_BOOLEAN: | ||
$output .= 'null'; | ||
break; | ||
case self::TYPE_STRING: | ||
$output .= "''"; | ||
break; | ||
case self::TYPE_ARRAY: | ||
$output .= '[]'; | ||
break; | ||
case self::TYPE_OBJECT: | ||
$output .= '{}'; | ||
break; | ||
case self::TYPE_FILE: | ||
$output .= "await pickSingle()"; | ||
break; | ||
} | ||
} else { | ||
switch ($type) { | ||
case self::TYPE_NUMBER: | ||
case self::TYPE_INTEGER: | ||
case self::TYPE_ARRAY: | ||
case self::TYPE_OBJECT: | ||
$output .= $example; | ||
break; | ||
case self::TYPE_BOOLEAN: | ||
$output .= ($example) ? 'true' : 'false'; | ||
break; | ||
case self::TYPE_STRING: | ||
$output .= "'{$example}'"; | ||
break; | ||
case self::TYPE_FILE: | ||
$output .= "await pickSingle()"; | ||
break; | ||
} | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
public function getReturn(array $method, array $spec): string | ||
{ | ||
if ($method['type'] === 'webAuth') { | ||
return 'void | URL'; | ||
} elseif ($method['type'] === 'location') { | ||
return 'URL'; | ||
} | ||
|
||
if (array_key_exists('responseModel', $method) && !empty($method['responseModel']) && $method['responseModel'] !== 'any') { | ||
$ret = 'Promise<'; | ||
|
||
if ( | ||
array_key_exists($method['responseModel'], $spec['definitions']) && | ||
array_key_exists('additionalProperties', $spec['definitions'][$method['responseModel']]) && | ||
!$spec['definitions'][$method['responseModel']]['additionalProperties'] | ||
) { | ||
$ret .= 'Models.'; | ||
} | ||
|
||
$ret .= $this->toPascalCase($method['responseModel']); | ||
|
||
$models = []; | ||
|
||
$this->populateGenerics($method['responseModel'], $spec, $models); | ||
|
||
$models = array_unique($models); | ||
$models = array_filter($models, fn ($model) => $model != $this->toPascalCase($method['responseModel'])); | ||
|
||
if (!empty($models)) { | ||
$ret .= '<' . implode(', ', $models) . '>'; | ||
} | ||
|
||
$ret .= '>'; | ||
|
||
return $ret; | ||
} | ||
return 'Promise<{}>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Publish to NPM | ||
|
||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
# Setup Node.js environment | ||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
# Determine release tag based on the tag name | ||
- name: Determine release tag | ||
id: release_tag | ||
run: | | ||
if [[ "${{ github.ref }}" == *"-rc"* ]]; then | ||
echo "tag=next" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "tag=latest" >> "$GITHUB_OUTPUT" | ||
fi | ||
|
||
# Install dependencies (if any) and build your project (if necessary) | ||
- name: Install dependencies and build | ||
run: | | ||
npm install | ||
npm run build | ||
|
||
# Publish to NPM with the appropriate tag | ||
- name: Publish | ||
run: npm publish --tag ${{ steps.release_tag.outputs.tag }} | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{sdk.changelog}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{sdk.licenseContent | raw}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# {{ spec.title }} {{sdk.name}} SDK | ||
|
||
![License](https://img.shields.io/github/license/{{ sdk.gitUserName|url_encode }}/{{ sdk.gitRepoName|url_encode }}.svg?style=flat-square) | ||
![Version](https://img.shields.io/badge/api%20version-{{ spec.version|url_encode }}-blue.svg?style=flat-square) | ||
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) | ||
{% if sdk.twitterHandle %} | ||
[![Twitter Account](https://img.shields.io/twitter/follow/{{ sdk.twitterHandle }}?color=00acee&label=twitter&style=flat-square)](https://twitter.com/{{ sdk.twitterHandle }}) | ||
{% endif %} | ||
{% if sdk.discordChannel %} | ||
[![Discord](https://img.shields.io/discord/{{ sdk.discordChannel }}?label=discord&style=flat-square)]({{ sdk.discordUrl }}) | ||
{% endif %} | ||
{% if sdk.warning %} | ||
|
||
{{ sdk.warning|raw }} | ||
{% endif %} | ||
|
||
{{ sdk.description }} | ||
|
||
{% if sdk.logo %} | ||
![{{ spec.title }}]({{ sdk.logo }}) | ||
{% endif %} | ||
|
||
## Installation | ||
|
||
To install | ||
|
||
```bash | ||
npx expo install react-native-appwrite react-native-url-polyfill | ||
``` | ||
|
||
{% if sdk.gettingStarted %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did we add this? I can't find it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
||
{{ sdk.gettingStarted|raw }} | ||
{% endif %} | ||
|
||
## Contribution | ||
|
||
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request. | ||
|
||
## License | ||
|
||
Please see the [{{spec.licenseName}} license]({{spec.licenseURL}}) file for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have it in the
getting started section