Skip to content

Commit 63b6808

Browse files
Merge pull request #671 from appwrite/feat-flutter-dart-docs
Add inline doc comments to the Dart and Flutter SDKs
2 parents 31610b9 + 3801bf9 commit 63b6808

21 files changed

+245
-46
lines changed

templates/dart/README.md.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![pub package](https://img.shields.io/pub/v/{{ language.params.packageName }}.svg?style=flat-square)](https://pub.dartlang.org/packages/{{ language.params.packageName }})
44
![License](https://img.shields.io/github/license/{{ sdk.gitUserName|url_encode }}/{{ sdk.gitRepoName|url_encode }}.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-{{ spec.version|url_encode }}-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-{{spec.version | split('.') | slice(0,2) | join('.') ~ '.x' | url_encode}}-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
{% if sdk.twitterHandle %}
88
[![Twitter Account](https://img.shields.io/twitter/follow/{{ sdk.twitterHandle }}?color=00acee&label=twitter&style=flat-square)](https://twitter.com/{{ sdk.twitterHandle }})

templates/dart/lib/id.dart.twig

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
part of {{ language.params.packageName }};
22

3+
/// Helper class to generate ID strings for resources.
34
class ID {
4-
ID._();
5-
6-
static String unique() {
7-
return 'unique()';
8-
}
5+
ID._();
96

10-
static String custom(String id) {
11-
return id;
12-
}
7+
/// Have Appwrite generate a unique ID for you.
8+
static String unique() {
9+
return 'unique()';
10+
}
11+
12+
/// Uses [id] as the ID for the resource.
13+
static String custom(String id) {
14+
return id;
15+
}
1316
}

templates/dart/lib/models.dart.twig

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// {{spec.title | caseUcfirst}} Models
12
library {{ language.params.packageName }}.models;
23

34
part 'src/models/model.dart';

templates/dart/lib/package.dart.twig

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/// {{spec.title | caseUcfirst}} {{sdk.name}} SDK
2+
///
3+
/// This SDK is compatible with Appwrite server version {{spec.version | split('.') | slice(0,2) | join('.') ~ '.x' }}.
4+
/// For older versions, please check
5+
/// [previous releases](https://github.com/{{sdk.gitUserName}}/{{sdk.gitRepoName}}/releases).
16
library {{ language.params.packageName }};
27

38
import 'dart:async';
+29-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
part of {{ language.params.packageName }};
22

3+
/// Helper class to generate permission strings for resources.
34
class Permission {
4-
Permission._();
5+
Permission._();
56

6-
static String read(String role) {
7-
return 'read("$role")';
8-
}
9-
static String write(String role) {
10-
return 'write("$role")';
11-
}
12-
static String create(String role) {
13-
return 'create("$role")';
14-
}
15-
static String update(String role) {
16-
return 'update("$role")';
17-
}
18-
static String delete(String role) {
19-
return 'delete("$role")';
20-
}
7+
/// Read permission for provided [role]
8+
static String read(String role) {
9+
return 'read("$role")';
10+
}
11+
12+
/// Write permission for provided [role]
13+
///
14+
/// This is an alias of update, delete, and possibly create.
15+
/// Don't use write in combination with update, delete, or create.
16+
static String write(String role) {
17+
return 'write("$role")';
18+
}
19+
20+
/// Create permission for provided [role]
21+
static String create(String role) {
22+
return 'create("$role")';
23+
}
24+
25+
/// Update permission for provided [role]
26+
static String update(String role) {
27+
return 'update("$role")';
28+
}
29+
30+
/// Delete permission for provided [role]
31+
static String delete(String role) {
32+
return 'delete("$role")';
33+
}
2134
}

templates/dart/lib/query.dart.twig

+63-7
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,117 @@
11
part of {{ language.params.packageName }};
22

3+
/// Helper class to generate query strings.
34
class Query {
4-
Query._();
5-
5+
Query._();
6+
7+
/// Filter resources where [attribute] is equal to [value].
8+
///
9+
/// [value] can be a single value or a list. If a list is used
10+
/// the query will return resources where [attribute] is equal
11+
/// to any of the values in the list.
612
static String equal(String attribute, dynamic value) =>
713
_addQuery(attribute, 'equal', value);
814

15+
/// Filter resources where [attribute] is not equal to [value].
16+
///
17+
/// [value] can be a single value or a list. If a list is used
18+
/// the query will return resources where [attribute] is equal
19+
/// to any of the values in the list.
920
static String notEqual(String attribute, dynamic value) =>
1021
_addQuery(attribute, 'notEqual', value);
1122

23+
/// Filter resources where [attribute] is less than [value].
24+
///
25+
/// [value] can be a single value or a list. If a list is used
26+
/// the query will return resources where [attribute] is equal
27+
/// to any of the values in the list.
1228
static String lessThan(String attribute, dynamic value) =>
1329
_addQuery(attribute, 'lessThan', value);
1430

31+
/// Filter resources where [attribute] is less than or equal to [value].
32+
///
33+
/// [value] can be a single value or a list. If a list is used
34+
/// the query will return resources where [attribute] is equal
35+
/// to any of the values in the list.
1536
static String lessThanEqual(String attribute, dynamic value) =>
1637
_addQuery(attribute, 'lessThanEqual', value);
1738

39+
/// Filter resources where [attribute] is greater than [value].
40+
///
41+
/// [value] can be a single value or a list. If a list is used
42+
/// the query will return resources where [attribute] is equal
43+
/// to any of the values in the list.
1844
static String greaterThan(String attribute, dynamic value) =>
1945
_addQuery(attribute, 'greaterThan', value);
2046

47+
/// Filter resources where [attribute] is greater than or equal to [value].
48+
///
49+
/// [value] can be a single value or a list. If a list is used
50+
/// the query will return resources where [attribute] is equal
51+
/// to any of the values in the list.
2152
static String greaterThanEqual(String attribute, dynamic value) =>
2253
_addQuery(attribute, 'greaterThanEqual', value);
2354

55+
/// Filter resources where by searching [attribute] for [value].
56+
///
57+
/// A fulltext index on [attribute] is required for this query to work.
2458
static String search(String attribute, String value) =>
2559
_addQuery(attribute, 'search', value);
2660

61+
/// Filter resources where [attribute] is null.
2762
static String isNull(String attribute) => 'isNull("$attribute")';
2863

64+
/// Filter resources where [attribute] is not null.
2965
static String isNotNull(String attribute) => 'isNotNull("$attribute")';
3066

67+
/// Filter resources where [attribute] is between [start] and [end] (inclusive).
3168
static String between(String attribute, dynamic start, dynamic end) =>
3269
_addQuery(attribute, 'between', [start, end]);
3370

71+
/// Filter resources where [attribute] starts with [value].
3472
static String startsWith(String attribute, String value) =>
3573
_addQuery(attribute, 'startsWith', value);
3674

75+
/// Filter resources where [attribute] ends with [value].
3776
static String endsWith(String attribute, String value) =>
3877
_addQuery(attribute, 'endsWith', value);
3978

40-
static String select(List<String> attributes) => 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])';
79+
/// Specify which attributes should be returned by the API call.
80+
static String select(List<String> attributes) =>
81+
'select([${attributes.map((attr) => "\"$attr\"").join(",")}])';
4182

83+
/// Sort results by [attribute] ascending.
4284
static String orderAsc(String attribute) => 'orderAsc("$attribute")';
4385

86+
/// Sort results by [attribute] descending.
4487
static String orderDesc(String attribute) => 'orderDesc("$attribute")';
4588

89+
/// Return results before [id].
90+
///
91+
/// Refer to the [Cursor Based Pagination]({{sdk.url}}/docs/pagination#cursor-pagination)
92+
/// docs for more information.
4693
static String cursorBefore(String id) => 'cursorBefore("$id")';
4794

95+
/// Return results after [id].
96+
///
97+
/// Refer to the [Cursor Based Pagination]({{sdk.url}}/docs/pagination#cursor-pagination)
98+
/// docs for more information.
4899
static String cursorAfter(String id) => 'cursorAfter("$id")';
49100

101+
/// Return only [limit] results.
50102
static String limit(int limit) => 'limit($limit)';
51103

104+
/// Return results from [offset].
105+
///
106+
/// Refer to the [Offset Pagination]({{sdk.url}}/docs/pagination#offset-pagination)
107+
/// docs for more information.
52108
static String offset(int offset) => 'offset($offset)';
53109

54110
static String _addQuery(String attribute, String method, dynamic value) => (value
55111
is List)
56-
? '$method("$attribute", [${value.map((item) => parseValues(item)).join(",")}])'
57-
: '$method("$attribute", [${parseValues(value)}])';
112+
? '$method("$attribute", [${value.map((item) => _parseValues(item)).join(",")}])'
113+
: '$method("$attribute", [${_parseValues(value)}])';
58114

59-
static String parseValues(dynamic value) =>
115+
static String _parseValues(dynamic value) =>
60116
(value is String) ? '"$value"' : '$value';
61-
}
117+
}

templates/dart/lib/role.dart.twig

+23
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,60 @@
11
part of {{ language.params.packageName }};
22

3+
/// Helper class to generate role strings for [Permission].
34
class Role {
45
Role._();
56

7+
/// Grants access to anyone.
8+
///
9+
/// This includes authenticated and unauthenticated users.
610
static String any() {
711
return 'any';
812
}
913

14+
/// Grants access to a specific user by user ID.
15+
///
16+
/// You can optionally pass verified or unverified for
17+
/// [status] to target specific types of users.
1018
static String user(String id, [String status = '']) {
1119
if(status.isEmpty) {
1220
return 'user:$id';
1321
}
1422
return 'user:$id/$status';
1523
}
1624

25+
/// Grants access to any authenticated or anonymous user.
26+
///
27+
/// You can optionally pass verified or unverified for
28+
/// [status] to target specific types of users.
1729
static String users([String status = '']) {
1830
if(status.isEmpty) {
1931
return 'users';
2032
}
2133
return 'users/$status';
2234
}
2335

36+
/// Grants access to any guest user without a session.
37+
///
38+
/// Authenticated users don't have access to this role.
2439
static String guests() {
2540
return 'guests';
2641
}
2742

43+
/// Grants access to a team by team ID.
44+
///
45+
/// You can optionally pass a role for [role] to target
46+
/// team members with the specified role.
2847
static String team(String id, [String role = '']) {
2948
if(role.isEmpty) {
3049
return 'team:$id';
3150
}
3251
return 'team:$id/$role';
3352
}
3453

54+
/// Grants access to a specific member of a team.
55+
///
56+
/// When the member is removed from the team, they will
57+
/// no longer have access.
3558
static String member(String id) {
3659
return 'member:$id';
3760
}

templates/dart/lib/services/service.dart.twig

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ part of {{ language.params.packageName }};
88
{% endmacro %}
99

1010
{%if service.description %}
11-
{{- service.description|dartComment}}
11+
{{- service.description|dartComment | split(' ///') | join('///')}}
1212
{% endif %}
1313
class {{ service.name | caseUcfirst }} extends Service {
1414
{{ service.name | caseUcfirst }}(super.client);
15-
1615
{% for method in service.methods %}
16+
1717
/// {{ method.title }}
18-
{%~ if method.description %}
1918
///
19+
{%~ if method.description %}
2020
{{ method.description | dartComment }}
21-
///
2221
{% endif %}
2322
{% if method.type == 'location' %}Future<Uint8List>{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future<models.{{method.responseModel | caseUcfirst | overrideIdentifier}}>{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async {
2423
final String path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %};
@@ -30,7 +29,6 @@ class {{ service.name | caseUcfirst }} extends Service {
3029
{% else %}
3130
{{ include('dart/base/requests/api.twig') }}
3231
{% endif %}
33-
3432
}
3533
{% endfor %}
3634
}

templates/dart/lib/src/client.dart.twig

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,47 @@ import 'client_stub.dart'
55
import 'response.dart';
66
import 'upload_progress.dart';
77

8+
/// [Client] that handles requests to {{spec.title | caseUcfirst}}
89
abstract class Client {
10+
/// The size for cunked uploads in bytes.
911
static const int CHUNK_SIZE = 5*1024*1024;
12+
13+
/// Holds configuration such as project.
1014
late Map<String, String> config;
1115
late String _endPoint;
1216

17+
/// {{spec.title | caseUcfirst}} endpoint.
1318
String get endPoint => _endPoint;
1419

20+
/// Initializes a [Client].
1521
factory Client(
1622
{String endPoint = '{{ spec.endpoint }}',
1723
bool selfSigned = false}) =>
1824
createClient(endPoint: endPoint, selfSigned: selfSigned);
1925

26+
/// Set self signed to [status].
27+
///
28+
/// If self signed is true, [Client] will ignore invalid certificates.
29+
/// This is helpful in environments where your {{spec.title | caseUcfirst}}
30+
/// instance does not have a valid SSL certificate.
2031
Client setSelfSigned({bool status = true});
2132

33+
/// Set the {{spec.title | caseUcfirst}} endpoint.
2234
Client setEndpoint(String endPoint);
2335

2436
{% for header in spec.global.headers %}
37+
/// Set {{header.key | caseUcfirst}}
2538
{% if header.description %}
39+
///
2640
/// {{header.description}}
2741
{% endif %}
2842
Client set{{header.key | caseUcfirst}}(value);
29-
{% endfor %}
3043

44+
{% endfor %}
45+
/// Add headers that should be sent with all API calls.
3146
Client addHeader(String key, String value);
3247

48+
/// Upload a file in chunks.
3349
Future<Response> chunkedUpload({
3450
required String path,
3551
required Map<String, dynamic> params,
@@ -39,6 +55,7 @@ abstract class Client {
3955
Function(UploadProgress)? onProgress,
4056
});
4157

58+
/// Send the API request.
4259
Future<Response> call(HttpMethod method, {
4360
String path = '',
4461
Map<String, String> headers = const {},

templates/dart/lib/src/enums.dart.twig

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/// HTTP methods.
12
enum HttpMethod { get, post, put, delete, patch }
23

34
extension HttpMethodString on HttpMethod {
5+
/// Returns the HTTP method in all caps.
46
String name() {
57
return toString().split('.').last.toUpperCase();
68
}

0 commit comments

Comments
 (0)