Skip to content

Commit

Permalink
Merge pull request #114 from muzzammilshahid/args-kwargs-abort
Browse files Browse the repository at this point in the history
Add args and kwargs in Abort message
  • Loading branch information
muzzammilshahid authored Jul 3, 2024
2 parents dcd579e + 595699f commit 69b8875
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions lib/src/messages/abort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,43 @@ abstract class IAbortFields {
Map<String, dynamic> get details;

String get reason;

List<dynamic> get args;

Map<String, dynamic> get kwargs;
}

class AbortFields implements IAbortFields {
AbortFields(this._details, this._reason);
AbortFields(
this._details,
this._reason, {
List<dynamic>? args,
Map<String, dynamic>? kwargs,
}) : _args = args ?? [],
_kwargs = kwargs ?? {};

final Map<String, dynamic> _details;
final String _reason;

final List<dynamic> _args;
final Map<String, dynamic> _kwargs;

@override
Map<String, dynamic> get details => _details;

@override
String get reason => _reason;

@override
List get args => _args;

@override
Map<String, dynamic> get kwargs => _kwargs;
}

class Abort implements Message {
Abort(Map<String, dynamic> details, String reason) {
_abortFields = AbortFields(details, reason);
Abort(Map<String, dynamic> details, String reason, {List<dynamic>? args, Map<String, dynamic>? kwargs}) {
_abortFields = AbortFields(details, reason, args: args, kwargs: kwargs);
}

Abort.withFields(this._abortFields);
Expand All @@ -34,11 +53,13 @@ class Abort implements Message {

static final _validationSpec = ValidationSpec(
minLength: 3,
maxLength: 3,
maxLength: 5,
message: text,
spec: {
1: validateDetails,
2: validateReason,
3: validateArgs,
4: validateKwargs,
},
);

Expand All @@ -51,7 +72,7 @@ class Abort implements Message {
static Abort parse(final List<dynamic> message) {
var fields = validateMessage(message, id, text, _validationSpec);

return Abort(fields.details!, fields.reason!);
return Abort(fields.details!, fields.reason!, args: fields.args, kwargs: fields.kwargs);
}

@override
Expand Down

0 comments on commit 69b8875

Please sign in to comment.