Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file:

```yml
dependencies:
appwrite: ^19.1.0
appwrite: ^21.0.0
```

You can install packages from the command line:
Expand Down
2 changes: 2 additions & 0 deletions lib/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ part 'src/enums/flag.dart';
part 'src/enums/execution_method.dart';
part 'src/enums/image_gravity.dart';
part 'src/enums/image_format.dart';
part 'src/enums/execution_trigger.dart';
part 'src/enums/execution_status.dart';
2 changes: 2 additions & 0 deletions lib/models.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// Appwrite Models
library appwrite.models;

import 'enums.dart' as enums;

part 'src/models/model.dart';
part 'src/models/row_list.dart';
part 'src/models/document_list.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
'x-sdk-name': 'Flutter',
'x-sdk-platform': 'client',
'x-sdk-language': 'flutter',
'x-sdk-version': '19.1.0',
'x-sdk-version': '21.0.0',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped a version

'X-Appwrite-Response-Format': '1.8.0',
};

Expand Down
2 changes: 1 addition & 1 deletion lib/src/client_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ClientIO extends ClientBase with ClientMixin {
'x-sdk-name': 'Flutter',
'x-sdk-platform': 'client',
'x-sdk-language': 'flutter',
'x-sdk-version': '19.1.0',
'x-sdk-version': '21.0.0',
'X-Appwrite-Response-Format': '1.8.0',
};

Expand Down
14 changes: 14 additions & 0 deletions lib/src/enums/execution_status.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
part of '../../enums.dart';

enum ExecutionStatus {
waiting(value: 'waiting'),
processing(value: 'processing'),
completed(value: 'completed'),
failed(value: 'failed');

const ExecutionStatus({required this.value});

final String value;

String toJson() => value;
}
13 changes: 13 additions & 0 deletions lib/src/enums/execution_trigger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
part of '../../enums.dart';

enum ExecutionTrigger {
http(value: 'http'),
schedule(value: 'schedule'),
event(value: 'event');

const ExecutionTrigger({required this.value});

final String value;

String toJson() => value;
}
2 changes: 1 addition & 1 deletion lib/src/models/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Document implements Model {
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
$permissions: List.from(map['\$permissions'] ?? []),
data: map,
data: map["data"] ?? map,
);
}

Expand Down
16 changes: 10 additions & 6 deletions lib/src/models/execution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class Execution implements Model {
final String deploymentId;

/// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`.
final String trigger;
final enums.ExecutionTrigger trigger;

/// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`.
final String status;
final enums.ExecutionStatus status;

/// HTTP request method type.
final String requestMethod;
Expand Down Expand Up @@ -85,8 +85,12 @@ class Execution implements Model {
$permissions: List.from(map['\$permissions'] ?? []),
functionId: map['functionId'].toString(),
deploymentId: map['deploymentId'].toString(),
trigger: map['trigger'].toString(),
status: map['status'].toString(),
trigger: enums.ExecutionTrigger.values.firstWhere(
(e) => e.value == map['trigger'],
),
status: enums.ExecutionStatus.values.firstWhere(
(e) => e.value == map['status'],
),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle unknown enum values explicitly to avoid opaque StateError

firstWhere without orElse throws StateError on unknown/nullable values. Emit a clear error (or use the enum’s fromJson helper if added).

Apply this diff:

-      trigger: enums.ExecutionTrigger.values.firstWhere(
-        (e) => e.value == map['trigger'],
-      ),
-      status: enums.ExecutionStatus.values.firstWhere(
-        (e) => e.value == map['status'],
-      ),
+      trigger: enums.ExecutionTrigger.values.firstWhere(
+        (e) => e.value == map['trigger'],
+        orElse: () => throw ArgumentError.value(
+          map['trigger'],
+          'trigger',
+          'Unknown ExecutionTrigger',
+        ),
+      ),
+      status: enums.ExecutionStatus.values.firstWhere(
+        (e) => e.value == map['status'],
+        orElse: () => throw ArgumentError.value(
+          map['status'],
+          'status',
+          'Unknown ExecutionStatus',
+        ),
+      ),

If you add enums’ fromJson as suggested, prefer:

-      trigger: enums.ExecutionTrigger.values.firstWhere( ... ),
-      status: enums.ExecutionStatus.values.firstWhere( ... ),
+      trigger: enums.ExecutionTrigger.fromJson(map['trigger']),
+      status: enums.ExecutionStatus.fromJson(map['status']),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
trigger: enums.ExecutionTrigger.values.firstWhere(
(e) => e.value == map['trigger'],
),
status: enums.ExecutionStatus.values.firstWhere(
(e) => e.value == map['status'],
),
trigger: enums.ExecutionTrigger.values.firstWhere(
(e) => e.value == map['trigger'],
orElse: () => throw ArgumentError.value(
map['trigger'],
'trigger',
'Unknown ExecutionTrigger',
),
),
status: enums.ExecutionStatus.values.firstWhere(
(e) => e.value == map['status'],
orElse: () => throw ArgumentError.value(
map['status'],
'status',
'Unknown ExecutionStatus',
),
),
🤖 Prompt for AI Agents
In lib/src/models/execution.dart around lines 88 to 93, firstWhere is used
without orElse which will throw a vague StateError for unknown or null enum
values; change these lookups to either call a dedicated fromJson helper on the
enums or add an orElse that throws a clear, descriptive error (e.g.
FormatException or ArgumentError) indicating the invalid trigger/status and the
offending map value; ensure the error message includes the map key and value so
callers can diagnose malformed or unknown enum values.

requestMethod: map['requestMethod'].toString(),
requestPath: map['requestPath'].toString(),
requestHeaders: List<Headers>.from(
Expand All @@ -112,8 +116,8 @@ class Execution implements Model {
"\$permissions": $permissions,
"functionId": functionId,
"deploymentId": deploymentId,
"trigger": trigger,
"status": status,
"trigger": trigger.value,
"status": status.value,
"requestMethod": requestMethod,
"requestPath": requestPath,
"requestHeaders": requestHeaders.map((p) => p.toMap()).toList(),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Preferences implements Model {
Preferences({required this.data});

factory Preferences.fromMap(Map<String, dynamic> map) {
return Preferences(data: map);
return Preferences(data: map["data"] ?? map);
}

Map<String, dynamic> toMap() {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Row implements Model {
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
$permissions: List.from(map['\$permissions'] ?? []),
data: map,
data: map["data"] ?? map,
);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: appwrite
version: 19.1.0
version: 21.0.0
description: Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API
homepage: https://appwrite.io
repository: https://github.com/appwrite/sdk-for-flutter
Expand Down
9 changes: 5 additions & 4 deletions test/src/models/execution_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appwrite/models.dart';
import 'package:appwrite/enums.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
Expand All @@ -11,8 +12,8 @@ void main() {
$permissions: [],
functionId: '5e5ea6g16897e',
deploymentId: '5e5ea5c16897e',
trigger: 'http',
status: 'processing',
trigger: ExecutionTrigger.http,
status: ExecutionStatus.waiting,
requestMethod: 'GET',
requestPath: '/articles?id=5',
requestHeaders: [],
Expand All @@ -33,8 +34,8 @@ void main() {
expect(result.$permissions, []);
expect(result.functionId, '5e5ea6g16897e');
expect(result.deploymentId, '5e5ea5c16897e');
expect(result.trigger, 'http');
expect(result.status, 'processing');
expect(result.trigger, ExecutionTrigger.http);
expect(result.status, ExecutionStatus.waiting);
expect(result.requestMethod, 'GET');
expect(result.requestPath, '/articles?id=5');
expect(result.requestHeaders, []);
Expand Down