Skip to content

Commit 5dbaec8

Browse files
committed
SDK binary support for executions
1 parent 0ab2531 commit 5dbaec8

File tree

146 files changed

+11364
-11707
lines changed

Some content is hidden

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

146 files changed

+11364
-11707
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file:
2323

2424
```yml
2525
dependencies:
26-
dart_appwrite: ^12.1.0
26+
dart_appwrite: ^13.0.0-rc1
2727
```
2828
2929
You can install packages from the command line:

docs/examples/functions/create-deployment.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Functions functions = Functions(client);
1010

1111
Deployment result = await functions.createDeployment(
1212
functionId: '<FUNCTION_ID>',
13-
code: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'),
13+
code: Payload.fromFile(path: '/path/to/file.png'),
1414
activate: false,
1515
entrypoint: '<ENTRYPOINT>', // (optional)
1616
commands: '<COMMANDS>', // (optional)

docs/examples/functions/create-execution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Functions functions = Functions(client);
99

1010
Execution result = await functions.createExecution(
1111
functionId: '<FUNCTION_ID>',
12-
body: '<BODY>', // (optional)
12+
body: Payload.fromJson({ 'x': 'y' }), // (optional)
1313
xasync: false, // (optional)
1414
path: '<PATH>', // (optional)
1515
method: ExecutionMethod.gET, // (optional)

docs/examples/storage/create-file.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ Storage storage = Storage(client);
1111
File result = await storage.createFile(
1212
bucketId: '<BUCKET_ID>',
1313
fileId: '<FILE_ID>',
14-
file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'),
14+
file: Payload.fromFile(path: '/path/to/file.png'),
1515
permissions: ["read("any")"], // (optional)
1616
);

lib/client_browser.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export 'src/client_browser.dart';
1+
export 'src/client_browser.dart';

lib/client_io.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export 'src/client_io.dart';
1+
export 'src/client_io.dart';

lib/dart_appwrite.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// Appwrite Dart SDK
22
///
3-
/// This SDK is compatible with Appwrite server version 1.6.x.
3+
/// This SDK is compatible with Appwrite server version 1.6.x.
44
/// For older versions, please check
55
/// [previous releases](https://github.com/appwrite/sdk-for-dart/releases).
66
library dart_appwrite;
@@ -12,16 +12,16 @@ import 'dart:convert';
1212

1313
import 'src/enums.dart';
1414
import 'src/service.dart';
15-
import 'src/input_file.dart';
1615
import 'src/upload_progress.dart';
1716
import 'models.dart' as models;
1817
import 'enums.dart' as enums;
18+
import 'payload.dart';
1919

2020
export 'src/response.dart';
2121
export 'src/client.dart';
2222
export 'src/exception.dart';
23-
export 'src/input_file.dart';
2423
export 'src/upload_progress.dart';
24+
export 'payload.dart';
2525

2626
part 'query.dart';
2727
part 'permission.dart';

lib/id.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class ID {
1010
final now = DateTime.now();
1111
final sec = (now.millisecondsSinceEpoch / 1000).floor();
1212
final usec = now.microsecondsSinceEpoch - (sec * 1000000);
13-
return sec.toRadixString(16) + usec.toRadixString(16).padLeft(5, '0');
13+
return sec.toRadixString(16) +
14+
usec.toRadixString(16).padLeft(5, '0');
1415
}
1516

1617
// Generate a unique ID with padding to have a longer ID

lib/models.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/// Appwrite Models
22
library dart_appwrite.models;
33

4+
import 'payload.dart';
5+
46
part 'src/models/model.dart';
57
part 'src/models/document_list.dart';
68
part 'src/models/collection_list.dart';

lib/payload.dart

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import 'dart:convert';
2+
import 'src/exception.dart';
3+
4+
class Payload {
5+
late final String? path;
6+
late final List<int>? data;
7+
final String? filename;
8+
9+
Payload._({this.path, this.filename, this.data}) {
10+
if (path == null && data == null) {
11+
throw AppwriteException('One of `path` or `data` is required');
12+
}
13+
}
14+
15+
/// Convert to binary, with optional offset and length
16+
List<int> toBinary({int offset = 0, int? length}) {
17+
if(data == null) {
18+
throw AppwriteException('`data` is not defined.');
19+
}
20+
if(offset == 0 && length == null) {
21+
return data!;
22+
} else if (length == null) {
23+
return data!.sublist(offset);
24+
} else {
25+
return data!.sublist(offset, offset + length);
26+
}
27+
}
28+
29+
/// Convert binary data to string (utf8)
30+
@override
31+
String toString() {
32+
if(data == null) {
33+
return '';
34+
}
35+
return utf8.decode(data!);
36+
}
37+
38+
/// Convert binary data to JSON object
39+
Map<String, dynamic> toJson() {
40+
try {
41+
return jsonDecode(toString()); // Decode the string to JSON
42+
} catch (e) {
43+
throw FormatException('Failed to parse JSON: ${e.toString()}');
44+
}
45+
}
46+
47+
/// Create a Payload from binary data
48+
factory Payload.fromBinary({
49+
required List<int> data,
50+
String? filename,
51+
}) {
52+
return Payload._(data: data, filename: filename);
53+
}
54+
55+
/// Create a Payload from a file
56+
factory Payload.fromFile({required String path, String? filename}) {
57+
return Payload._(path: path, filename: filename);
58+
}
59+
60+
/// Create a Payload from a JSON object
61+
factory Payload.fromJson({
62+
required Map<String, dynamic> data,
63+
String? filename,
64+
}) {
65+
final jsonString = jsonEncode(data);
66+
return Payload.fromString(string: jsonString, filename: filename);
67+
}
68+
69+
/// Create a Payload from a string
70+
factory Payload.fromString({required String string, String? filename}) {
71+
final data = utf8.encode(string);
72+
return Payload._(data: data, filename: filename);
73+
}
74+
}

lib/query.dart

+19-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
part of 'dart_appwrite.dart';
22

3+
34
/// Helper class to generate query strings.
45
class Query {
56
final String method;
@@ -13,11 +14,11 @@ class Query {
1314
'method': method,
1415
};
1516

16-
if (attribute != null) {
17+
if(attribute != null) {
1718
map['attribute'] = attribute;
1819
}
19-
20-
if (values != null) {
20+
21+
if(values != null) {
2122
map['values'] = values is List ? values : [values];
2223
}
2324

@@ -28,7 +29,7 @@ class Query {
2829
String toString() => jsonEncode(toJson());
2930

3031
/// Filter resources where [attribute] is equal to [value].
31-
///
32+
///
3233
/// [value] can be a single value or a list. If a list is used
3334
/// the query will return resources where [attribute] is equal
3435
/// to any of the values in the list.
@@ -60,12 +61,10 @@ class Query {
6061
Query._('search', attribute, value).toString();
6162

6263
/// Filter resources where [attribute] is null.
63-
static String isNull(String attribute) =>
64-
Query._('isNull', attribute).toString();
64+
static String isNull(String attribute) => Query._('isNull', attribute).toString();
6565

6666
/// Filter resources where [attribute] is not null.
67-
static String isNotNull(String attribute) =>
68-
Query._('isNotNull', attribute).toString();
67+
static String isNotNull(String attribute) => Query._('isNotNull', attribute).toString();
6968

7069
/// Filter resources where [attribute] is between [start] and [end] (inclusive).
7170
static String between(String attribute, dynamic start, dynamic end) =>
@@ -85,46 +84,40 @@ class Query {
8584
Query._('contains', attribute, value).toString();
8685

8786
static String or(List<String> queries) =>
88-
Query._('or', null, queries.map((query) => jsonDecode(query)).toList())
89-
.toString();
87+
Query._('or', null, queries.map((query) => jsonDecode(query)).toList()).toString();
9088

9189
static String and(List<String> queries) =>
92-
Query._('and', null, queries.map((query) => jsonDecode(query)).toList())
93-
.toString();
90+
Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString();
9491

9592
/// Specify which attributes should be returned by the API call.
9693
static String select(List<String> attributes) =>
9794
Query._('select', null, attributes).toString();
9895

9996
/// Sort results by [attribute] ascending.
100-
static String orderAsc(String attribute) =>
101-
Query._('orderAsc', attribute).toString();
97+
static String orderAsc(String attribute) => Query._('orderAsc', attribute).toString();
10298

10399
/// Sort results by [attribute] descending.
104-
static String orderDesc(String attribute) =>
105-
Query._('orderDesc', attribute).toString();
100+
static String orderDesc(String attribute) => Query._('orderDesc', attribute).toString();
106101

107102
/// Return results before [id].
108-
///
103+
///
109104
/// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination)
110105
/// docs for more information.
111-
static String cursorBefore(String id) =>
112-
Query._('cursorBefore', null, id).toString();
106+
static String cursorBefore(String id) => Query._('cursorBefore', null, id).toString();
113107

114108
/// Return results after [id].
115-
///
109+
///
116110
/// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination)
117111
/// docs for more information.
118-
static String cursorAfter(String id) =>
119-
Query._('cursorAfter', null, id).toString();
112+
static String cursorAfter(String id) => Query._('cursorAfter', null, id).toString();
120113

121114
/// Return only [limit] results.
122115
static String limit(int limit) => Query._('limit', null, limit).toString();
123116

124117
/// Return results from [offset].
125-
///
118+
///
126119
/// Refer to the [Offset Pagination](https://appwrite.io/docs/pagination#offset-pagination)
127120
/// docs for more information.
128-
static String offset(int offset) =>
129-
Query._('offset', null, offset).toString();
130-
}
121+
static String offset(int offset) => Query._('offset', null, offset).toString();
122+
123+
}

lib/role.dart

+53-53
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,65 @@ part of 'dart_appwrite.dart';
22

33
/// Helper class to generate role strings for [Permission].
44
class Role {
5-
Role._();
6-
7-
/// Grants access to anyone.
8-
///
9-
/// This includes authenticated and unauthenticated users.
10-
static String any() {
11-
return 'any';
12-
}
5+
Role._();
6+
7+
/// Grants access to anyone.
8+
///
9+
/// This includes authenticated and unauthenticated users.
10+
static String any() {
11+
return 'any';
12+
}
1313

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.
18-
static String user(String id, [String status = '']) {
19-
if (status.isEmpty) {
20-
return 'user:$id';
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.
18+
static String user(String id, [String status = '']) {
19+
if(status.isEmpty) {
20+
return 'user:$id';
21+
}
22+
return 'user:$id/$status';
2123
}
22-
return 'user:$id/$status';
23-
}
2424

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.
29-
static String users([String status = '']) {
30-
if (status.isEmpty) {
31-
return 'users';
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.
29+
static String users([String status = '']) {
30+
if(status.isEmpty) {
31+
return 'users';
32+
}
33+
return 'users/$status';
3234
}
33-
return 'users/$status';
34-
}
3535

36-
/// Grants access to any guest user without a session.
37-
///
38-
/// Authenticated users don't have access to this role.
39-
static String guests() {
40-
return 'guests';
41-
}
36+
/// Grants access to any guest user without a session.
37+
///
38+
/// Authenticated users don't have access to this role.
39+
static String guests() {
40+
return 'guests';
41+
}
4242

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.
47-
static String team(String id, [String role = '']) {
48-
if (role.isEmpty) {
49-
return 'team:$id';
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.
47+
static String team(String id, [String role = '']) {
48+
if(role.isEmpty) {
49+
return 'team:$id';
50+
}
51+
return 'team:$id/$role';
5052
}
51-
return 'team:$id/$role';
52-
}
5353

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.
58-
static String member(String id) {
59-
return 'member:$id';
60-
}
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.
58+
static String member(String id) {
59+
return 'member:$id';
60+
}
6161

62-
/// Grants access to a user with the specified label.
63-
static String label(String name) {
64-
return 'label:$name';
65-
}
66-
}
62+
/// Grants access to a user with the specified label.
63+
static String label(String name) {
64+
return 'label:$name';
65+
}
66+
}

0 commit comments

Comments
 (0)