Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Channel Message to subscribeTo #85

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 .github/workflows/build-client-dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: flutter-actions/setup-flutter@v2
with:
channel: stable
version: 3.7.12
version: 3.10.6
- name: Install dependencies
run: flutter pub get
- name: Run test
Expand Down
1 change: 1 addition & 0 deletions clients/client-dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CHANGELOG

## [2.0.0] - Add Channel Message to `subscribeTo`
## [1.0.2] - Add Dart Code Linter
## [1.0.1] - Update of dependencies to comply with null safety definition
## [1.0.0] - First version of channel_sender_client
Expand Down
111 changes: 4 additions & 107 deletions clients/client-dart/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,4 @@
include: package:flutter_lints/flutter.yaml

linter:
rules:
avoid_print: true
avoid_unnecessary_containers: true
avoid_web_libraries_in_flutter: true
no_logic_in_create_state: false
prefer_const_constructors: true
prefer_const_constructors_in_immutables: true
prefer_const_declarations: true
prefer_const_literals_to_create_immutables: true
sized_box_for_whitespace: true
use_full_hex_values_for_flutter_colors: true
always_declare_return_types: true
cancel_subscriptions: true
close_sinks: true
comment_references: false
one_member_abstracts: false
only_throw_errors: true
package_api_docs: true
prefer_single_quotes: true
sort_child_properties_last: true
camel_case_types: true
library_names: true
file_names: true
library_prefixes: true
non_constant_identifier_names: true
constant_identifier_names: false
directives_ordering: true
curly_braces_in_flow_control_structures: true
slash_for_doc_comments: false
prefer_interpolation_to_compose_strings: true
prefer_collection_literals: true
avoid_function_literals_in_foreach_calls: false
avoid_init_to_null: true
prefer_initializing_formals: true
type_init_formals: true
empty_constructor_bodies: true
empty_statements: true
unnecessary_new: true
unnecessary_this: true
unnecessary_const: true
unnecessary_overrides: true
unnecessary_parenthesis: true
unnecessary_getters_setters: true
avoid_setters_without_getters: true
avoid_return_types_on_setters: true
parameter_assignments: true
prefer_function_declarations_over_variables: false
unawaited_futures: true
prefer_relative_imports: true
annotate_overrides: false
overridden_fields: false

analyzer:
errors:
missing_required_param: error
Expand All @@ -64,57 +10,8 @@ analyzer:
todo: warning
plugins:
- dart_code_linter

dart_code_linter:
metrics:
cyclomatic-complexity: 20
maximum-nesting-level: 5
maintainability-index: 50
number-of-methods: 10
number-of-parameters: 4
source-lines-of-code: 250
metrics-exclude:
- test/**
rules:
- avoid-non-null-assertion
- avoid-dynamic
- avoid-returning-widgets
- avoid-nested-conditional-expressions
- avoid-unnecessary-type-casts
- avoid-unnecessary-conditionals
- avoid-unused-parameters
- missing-test-assertion
- newline-before-return
- no-boolean-literal-compare
- no-empty-block
- no-equal-then-else
- no-magic-number
- prefer-trailing-comma
- prefer-conditional-expressions
- prefer-immediate-return
- prefer-moving-to-variable
- format-comment:
only-doc-comments: true
- member-ordering:
order:
- constructors
- public-fields
- private-fields
- close-method
- dispose-method
widgets-order:
- constructor
- build-method
- init-state-method
- did-change-dependencies-method
- did-update-widget-method
- dispose-method
#Flutter
- always-remove-listener
- avoid-unnecessary-setstate
- prefer-extracting-callbacks
- prefer-using-list-view

anti-patterns:
- long-method
- long-parameter-list
extends:
- package:dart_code_linter/presets/recommended.yaml

3 changes: 2 additions & 1 deletion clients/client-dart/lib/channel_sender_client.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export 'src/async_client.dart' show AsyncClient;
export 'src/async_config.dart' show AsyncConfig;
export 'src/async_config.dart' show AsyncConfig;
export 'src/channel_message.dart';
18 changes: 9 additions & 9 deletions clients/client-dart/lib/src/async_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ class AsyncClient {
}

StreamSubscription<ChannelMessage> subscribeTo(
String eventFilter, Function onData,
{Function? onError}) {
if (onError != null) {
return subscribeToMany([eventFilter], onData, onError: onError);
} else {
return subscribeToMany([eventFilter], onData);
}
String eventFilter,
Function(ChannelMessage) onData, {
Function? onError,
}) {
return onError != null
? subscribeToMany([eventFilter], onData, onError: onError)
: subscribeToMany([eventFilter], onData);
}

StreamSubscription<ChannelMessage> subscribeToMany(
Expand All @@ -123,11 +123,11 @@ class AsyncClient {
if (eventFilters == null || eventFilters.isEmpty) {
throw ArgumentError('Invalid event filter(s)');
} else {
eventFilters.forEach((element) {
for (var element in eventFilters) {
if (element.trim().isEmpty) {
throw ArgumentError('Invalid event filter');
}
});
}
}
if (onData == null) {
throw ArgumentError('Invalid onData function');
Expand Down
16 changes: 8 additions & 8 deletions clients/client-dart/lib/src/channel_message.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
class ChannelMessage {
ChannelMessage(this.messageId, this.correlationId, this.event, this.payload);

ChannelMessage.fromMap(Map<String, dynamic> map)
: messageId = map['message_id'],
correlationId = map['correlation_id'],
event = map['event'],
payload = map['payload'];

final String? messageId;
final String? correlationId;
final String? event;
dynamic payload;

ChannelMessage(this.messageId, this.correlationId, this.event, this.payload);

@override
String toString() {
return '{messageId: $messageId, correlationId: $correlationId, event: $event, payload: $payload }';
}

ChannelMessage.fromMap(dynamic map)
: messageId = map['message_id'],
correlationId = map['correlation_id'],
event = map['event'],
payload = map['payload'];
}
62 changes: 35 additions & 27 deletions clients/client-dart/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: e440ac42679dfc04bbbefb58ed225c994bc7e07fccc8a68ec7d3631a127e5da9
sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a
url: "https://pub.dev"
source: hosted
version: "54.0.0"
version: "61.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: "2c2e3721ee9fb36de92faa060f3480c81b23e904352b087e5c64224b1a044427"
sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562
url: "https://pub.dev"
source: hosted
version: "5.6.0"
version: "5.13.0"
analyzer_plugin:
dependency: transitive
description:
Expand All @@ -29,10 +29,10 @@ packages:
dependency: transitive
description:
name: ansicolor
sha256: "607f8fa9786f392043f169898923e6c59b4518242b68b8862eb8a8b7d9c30b4a"
sha256: "50e982d500bc863e1d703448afdbf9e5a72eb48840a4f766fa361ffd6877055f"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.0.3"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -173,18 +173,18 @@ packages:
dependency: transitive
description:
name: csslib
sha256: b36c7f7e24c0bdf1bf9a3da461c837d1de64b9f8beb190c9011d8c72a3dfd745
sha256: "706b5707578e0c1b4b7550f64078f0a0f19dec3f50a178ffae7006b0a9ca58fb"
url: "https://pub.dev"
source: hosted
version: "0.17.2"
version: "1.0.0"
dart_code_linter:
dependency: "direct dev"
description:
name: dart_code_linter
sha256: e9c2764a39033ad808269092d8ae90b7c696598d2cd2138681550edf85be735f
sha256: "06fe4081e9e376917fbbdaf8f590162ae20bbcb29245e18a7f6f80557197ce16"
url: "https://pub.dev"
source: hosted
version: "1.1.1"
version: "1.1.4"
dart_style:
dependency: transitive
description:
Expand Down Expand Up @@ -245,18 +245,18 @@ packages:
dependency: transitive
description:
name: html
sha256: "58e3491f7bf0b6a4ea5110c0c688877460d1a6366731155c4a4580e7ded773e8"
sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a"
url: "https://pub.dev"
source: hosted
version: "0.15.3"
version: "0.15.4"
http:
dependency: transitive
description:
name: http
sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482"
sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525"
url: "https://pub.dev"
source: hosted
version: "0.13.5"
version: "1.1.0"
http_multi_server:
dependency: transitive
description:
Expand Down Expand Up @@ -373,18 +373,18 @@ packages:
dependency: transitive
description:
name: petitparser
sha256: "49392a45ced973e8d94a85fdb21293fbb40ba805fc49f2965101ae748a3683b4"
sha256: eeb2d1428ee7f4170e2bd498827296a18d4e7fc462b71727d111c0ac7707cfa6
url: "https://pub.dev"
source: hosted
version: "5.1.0"
version: "6.0.1"
platform:
dependency: transitive
description:
name: platform
sha256: "57c07bf82207aee366dfaa3867b3164e4f03a238a461a11b0e8a3a510d51203d"
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
version: "3.1.4"
pool:
dependency: transitive
description:
Expand All @@ -397,10 +397,10 @@ packages:
dependency: transitive
description:
name: process
sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09"
sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32"
url: "https://pub.dev"
source: hosted
version: "4.2.4"
version: "5.0.2"
pub_semver:
dependency: transitive
description:
Expand All @@ -413,10 +413,10 @@ packages:
dependency: transitive
description:
name: pub_updater
sha256: "05ae70703e06f7fdeb05f7f02dd680b8aad810e87c756a618f33e1794635115c"
sha256: "54e8dc865349059ebe7f163d6acce7c89eb958b8047e6d6e80ce93b13d7c9e60"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "0.4.0"
pubspec_parse:
dependency: transitive
description:
Expand Down Expand Up @@ -489,6 +489,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.0"
sprintf:
dependency: transitive
description:
name: sprintf
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -573,10 +581,10 @@ packages:
dependency: "direct main"
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
sha256: "8c951c9cb6504b2aa6b3666e6de504032d9baec24bf4cbabd3eea9edd73d4d77"
url: "https://pub.dev"
source: hosted
version: "3.0.7"
version: "4.3.2"
validators:
dependency: "direct main"
description:
Expand Down Expand Up @@ -621,10 +629,10 @@ packages:
dependency: transitive
description:
name: xml
sha256: "979ee37d622dec6365e2efa4d906c37470995871fe9ae080d967e192d88286b5"
sha256: af5e77e9b83f2f4adc5d3f0a4ece1c7f45a2467b695c2540381bac793e34e556
url: "https://pub.dev"
source: hosted
version: "6.2.2"
version: "6.4.2"
yaml:
dependency: transitive
description:
Expand All @@ -634,4 +642,4 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.19.0 <3.0.0"
dart: ">=3.0.0 <4.0.0"
Loading
Loading