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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 74 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)