From e1786408b7d9e67881eb4a343f4a21bde6053432 Mon Sep 17 00:00:00 2001 From: Klemen Tusar Date: Sat, 29 Jul 2023 22:42:08 +0100 Subject: [PATCH] :bookmark: release v7.0.0 (#454) --- .github/workflows/publish.yml | 2 + .github/workflows/publish_dry_run.yml | 2 + chopper/CHANGELOG.md | 5 + chopper/analysis_options.yaml | 21 -- chopper/lib/src/annotations.dart | 44 ++-- chopper/lib/src/base.dart | 4 +- chopper/lib/src/constants.dart | 2 +- chopper/lib/src/interceptor.dart | 8 +- chopper/lib/src/request.dart | 6 +- chopper/lib/src/response.dart | 2 +- chopper/lib/src/utils.dart | 2 +- chopper/pubspec.yaml | 27 ++- .../test/fixtures/http_response_fixture.dart | 2 +- chopper/test/fixtures/payload_fixture.dart | 2 +- chopper/test/fixtures/request_fixture.dart | 2 +- chopper/test/fixtures/response_fixture.dart | 2 +- chopper/test/helpers/payload.dart | 2 +- chopper_built_value/CHANGELOG.md | 4 + chopper_built_value/analysis_options.yaml | 21 -- chopper_built_value/pubspec.yaml | 23 +- chopper_generator/CHANGELOG.md | 6 + chopper_generator/analysis_options.yaml | 22 -- chopper_generator/lib/src/generator.dart | 9 +- chopper_generator/lib/src/utils.dart | 2 +- chopper_generator/pubspec.yaml | 31 ++- example/analysis_options.yaml | 20 -- .../lib/json_decode_service.activator.g.dart | 3 +- example/lib/json_decode_service.dart | 3 +- example/lib/json_decode_service.vm.g.dart | 12 +- example/lib/json_decode_service.worker.g.dart | 207 ++++++++++-------- example/pubspec.yaml | 23 +- 31 files changed, 235 insertions(+), 286 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 664fde42..41280a53 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,6 +43,8 @@ jobs: strategy: matrix: package: [ chopper, chopper_generator, chopper_built_value ] + fail-fast: true + max-parallel: 1 steps: - uses: dart-lang/setup-dart@v1 with: diff --git a/.github/workflows/publish_dry_run.yml b/.github/workflows/publish_dry_run.yml index b16ef582..14d51179 100644 --- a/.github/workflows/publish_dry_run.yml +++ b/.github/workflows/publish_dry_run.yml @@ -42,6 +42,8 @@ jobs: strategy: matrix: package: [ chopper, chopper_generator, chopper_built_value ] + fail-fast: true + max-parallel: 1 steps: - uses: dart-lang/setup-dart@v1 with: diff --git a/chopper/CHANGELOG.md b/chopper/CHANGELOG.md index d8a56152..b2846189 100644 --- a/chopper/CHANGELOG.md +++ b/chopper/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 7.0.0 + +- Require Dart 3.0 or later +- Add base, final, and interface modifiers to some classes ([#453](https://github.com/lejard-h/chopper/pull/453)) + ## 6.1.4 - Fix Multipart for List and List ([#439](https://github.com/lejard-h/chopper/pull/439)) diff --git a/chopper/analysis_options.yaml b/chopper/analysis_options.yaml index 7f5a674f..6f56a451 100644 --- a/chopper/analysis_options.yaml +++ b/chopper/analysis_options.yaml @@ -6,27 +6,6 @@ analyzer: - "**.chopper.dart" - "**.mocks.dart" - "example/**" - plugins: - - dart_code_metrics - -dart_code_metrics: - metrics: - cyclomatic-complexity: 20 - number-of-arguments: 4 - maximum-nesting-level: 5 - number-of-parameters: 7 - metrics-exclude: - - test/** - rules: - - newline-before-return - - no-boolean-literal-compare - - no-empty-block - - prefer-trailing-comma - - prefer-conditional-expressions - - no-equal-then-else - anti-patterns: - - long-method - - long-parameter-list linter: rules: diff --git a/chopper/lib/src/annotations.dart b/chopper/lib/src/annotations.dart index e7fa787c..9030d432 100644 --- a/chopper/lib/src/annotations.dart +++ b/chopper/lib/src/annotations.dart @@ -20,7 +20,7 @@ import 'package:meta/meta.dart'; /// /// See [Method] to define an HTTP request @immutable -class ChopperApi { +final class ChopperApi { /// A part of a URL that every request defined inside a class annotated with [ChopperApi] will be prefixed with. final String baseUrl; @@ -42,7 +42,7 @@ class ChopperApi { /// Future fetch(@Path() String param); /// ``` @immutable -class Path { +final class Path { /// Name is used to bind a method parameter to /// a URL path parameter. /// ```dart @@ -65,7 +65,7 @@ class Path { /// /// See [QueryMap] to pass an [Map] as value @immutable -class Query { +final class Query { /// Name is used to bind a method parameter to /// the query parameter. /// ```dart @@ -90,7 +90,7 @@ class Query { /// // something?foo=bar&list=1&list=2 /// ``` @immutable -class QueryMap { +final class QueryMap { const QueryMap(); } @@ -104,7 +104,7 @@ class QueryMap { /// The body can be of any type, but chopper does not automatically convert it to JSON. /// See [Converter] to apply conversion to the body. @immutable -class Body { +final class Body { const Body(); } @@ -117,7 +117,7 @@ class Body { /// Future fetch(@Header() String foo); /// ``` @immutable -class Header { +final class Header { /// Name is used to bind a method parameter to /// a header name. /// ```dart @@ -147,7 +147,7 @@ class Header { /// However, chopper will not automatically convert the body response to your type. /// A [Converter] needs to be specified for conversion. @immutable -class Method { +sealed class Method { /// HTTP method for the request final String method; @@ -207,7 +207,7 @@ class Method { /// Defines a method as an HTTP GET request. @immutable -class Get extends Method { +final class Get extends Method { const Get({ super.optionalBody = true, super.path, @@ -221,7 +221,7 @@ class Get extends Method { /// /// Use the [Body] annotation to pass data to send. @immutable -class Post extends Method { +final class Post extends Method { const Post({ super.optionalBody, super.path, @@ -233,7 +233,7 @@ class Post extends Method { /// Defines a method as an HTTP DELETE request. @immutable -class Delete extends Method { +final class Delete extends Method { const Delete({ super.optionalBody = true, super.path, @@ -247,7 +247,7 @@ class Delete extends Method { /// /// Use the [Body] annotation to pass data to send. @immutable -class Put extends Method { +final class Put extends Method { const Put({ super.optionalBody, super.path, @@ -260,7 +260,7 @@ class Put extends Method { /// Defines a method as an HTTP PATCH request. /// Use the [Body] annotation to pass data to send. @immutable -class Patch extends Method { +final class Patch extends Method { const Patch({ super.optionalBody, super.path, @@ -272,7 +272,7 @@ class Patch extends Method { /// Defines a method as an HTTP HEAD request. @immutable -class Head extends Method { +final class Head extends Method { const Head({ super.optionalBody = true, super.path, @@ -283,7 +283,7 @@ class Head extends Method { } @immutable -class Options extends Method { +final class Options extends Method { const Options({ super.optionalBody = true, super.path, @@ -330,7 +330,7 @@ typedef ConvertResponse = FutureOr Function(Response response); /// } /// ``` @immutable -class FactoryConverter { +final class FactoryConverter { final ConvertRequest? request; final ConvertResponse? response; @@ -349,7 +349,7 @@ class FactoryConverter { /// ``` /// Will be converted to `{ 'name': value }`. @immutable -class Field { +final class Field { /// Name can be use to specify the name of the field /// ```dart /// @Post(path: '/') @@ -367,7 +367,7 @@ class Field { /// Future fetch(@FieldMap List> query); /// ``` @immutable -class FieldMap { +final class FieldMap { const FieldMap(); } @@ -382,7 +382,7 @@ class FieldMap { /// Use [Part] annotation to send simple data. /// Use [PartFile] annotation to send `File` or `List`. @immutable -class Multipart { +final class Multipart { const Multipart(); } @@ -392,7 +392,7 @@ class Multipart { /// /// Also accepts `MultipartFile` (from package:http). @immutable -class Part { +final class Part { final String? name; const Part([this.name]); @@ -406,7 +406,7 @@ class Part { /// Future fetch(@PartMap() List query); /// ``` @immutable -class PartMap { +final class PartMap { const PartMap(); } @@ -423,7 +423,7 @@ class PartMap { /// - [String] (path of your file) /// - `MultipartFile` (from package:http) @immutable -class PartFile { +final class PartFile { final String? name; const PartFile([this.name]); @@ -437,7 +437,7 @@ class PartFile { /// Future fetch(@PartFileMap() List query); /// ``` @immutable -class PartFileMap { +final class PartFileMap { const PartFileMap(); } diff --git a/chopper/lib/src/base.dart b/chopper/lib/src/base.dart index 4fa556c2..27ab57fc 100644 --- a/chopper/lib/src/base.dart +++ b/chopper/lib/src/base.dart @@ -13,7 +13,7 @@ import 'package:meta/meta.dart'; Type _typeOf() => T; @visibleForTesting -final List allowedInterceptorsType = [ +const List allowedInterceptorsType = [ RequestInterceptor, RequestInterceptorFunc, ResponseInterceptor, @@ -26,7 +26,7 @@ final List allowedInterceptorsType = [ /// /// It manages registered services, encodes and decodes data, and intercepts /// requests and responses. -class ChopperClient { +base class ChopperClient { /// Base URL of each request of the registered services. /// E.g., the hostname of your service. final Uri baseUrl; diff --git a/chopper/lib/src/constants.dart b/chopper/lib/src/constants.dart index 52db96c8..e1c9d7f1 100644 --- a/chopper/lib/src/constants.dart +++ b/chopper/lib/src/constants.dart @@ -7,7 +7,7 @@ const String formEncodedHeaders = 'application/x-www-form-urlencoded'; // Represent the header for a json api response https://jsonapi.org/#mime-types const String jsonApiHeaders = 'application/vnd.api+json'; -abstract class HttpMethod { +abstract final class HttpMethod { static const String Get = 'GET'; static const String Post = 'POST'; static const String Put = 'PUT'; diff --git a/chopper/lib/src/interceptor.dart b/chopper/lib/src/interceptor.dart index b8595cea..185bfc97 100644 --- a/chopper/lib/src/interceptor.dart +++ b/chopper/lib/src/interceptor.dart @@ -31,7 +31,7 @@ import 'package:meta/meta.dart'; /// } /// ``` @immutable -abstract class ResponseInterceptor { +abstract interface class ResponseInterceptor { FutureOr onResponse(Response response); } @@ -58,7 +58,7 @@ abstract class ResponseInterceptor { /// /// (See [applyHeader(request, name, value)] and [applyHeaders(request, headers)].) @immutable -abstract class RequestInterceptor { +abstract interface class RequestInterceptor { FutureOr onRequest(Request request); } @@ -72,7 +72,7 @@ abstract class RequestInterceptor { /// /// See [JsonConverter] and [FormUrlEncodedConverter] for example implementations. @immutable -abstract class Converter { +abstract interface class Converter { /// Converts the received [Request] to a [Request] which has a body with the /// HTTP representation of the original body. FutureOr convertRequest(Request request); @@ -94,7 +94,7 @@ abstract class Converter { /// /// An `ErrorConverter` is called only on error responses /// (statusCode < 200 || statusCode >= 300) and before any [ResponseInterceptor]s. -abstract class ErrorConverter { +abstract interface class ErrorConverter { /// Converts the received [Response] to a [Response] which has a body with the /// HTTP representation of the original body. FutureOr convertError(Response response); diff --git a/chopper/lib/src/request.dart b/chopper/lib/src/request.dart index 736126ee..1441ef3d 100644 --- a/chopper/lib/src/request.dart +++ b/chopper/lib/src/request.dart @@ -7,7 +7,7 @@ import 'package:http/http.dart' as http; import 'package:meta/meta.dart'; /// This class represents an HTTP request that can be made with Chopper. -class Request extends http.BaseRequest with EquatableMixin { +base class Request extends http.BaseRequest with EquatableMixin { final Uri uri; final Uri baseUri; final dynamic body; @@ -232,7 +232,7 @@ class Request extends http.BaseRequest with EquatableMixin { /// Represents a part in a multipart request. @immutable -class PartValue with EquatableMixin { +final class PartValue with EquatableMixin { final T value; final String name; @@ -258,6 +258,6 @@ class PartValue with EquatableMixin { /// Represents a file [PartValue] in a multipart request. @immutable -class PartValueFile extends PartValue { +final class PartValueFile extends PartValue { const PartValueFile(super.name, super.value); } diff --git a/chopper/lib/src/response.dart b/chopper/lib/src/response.dart index 8f44e1c5..3ec5c499 100644 --- a/chopper/lib/src/response.dart +++ b/chopper/lib/src/response.dart @@ -16,7 +16,7 @@ import 'package:meta/meta.dart'; /// Future> fetchItem(); /// ``` @immutable -class Response with EquatableMixin { +base class Response with EquatableMixin { /// The [http.BaseResponse] from `package:http` that this [Response] wraps. final http.BaseResponse base; diff --git a/chopper/lib/src/utils.dart b/chopper/lib/src/utils.dart index c8853170..ce78291c 100644 --- a/chopper/lib/src/utils.dart +++ b/chopper/lib/src/utils.dart @@ -131,7 +131,7 @@ Iterable<_Pair> _iterableToQuery( String _normalizeValue(value) => Uri.encodeComponent(value?.toString() ?? ''); -class _Pair with EquatableMixin { +final class _Pair with EquatableMixin { final A first; final B second; final bool useBrackets; diff --git a/chopper/pubspec.yaml b/chopper/pubspec.yaml index 2af5cfbf..5a6d5859 100644 --- a/chopper/pubspec.yaml +++ b/chopper/pubspec.yaml @@ -1,30 +1,29 @@ name: chopper description: Chopper is an http client generator using source_gen, inspired by Retrofit -version: 6.1.4 +version: 7.0.0 documentation: https://hadrien-lejard.gitbook.io/chopper repository: https://github.com/lejard-h/chopper environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: equatable: ^2.0.5 - http: ">=0.13.0 <2.0.0" - logging: ^1.0.0 - meta: ^1.3.0 + http: ^1.1.0 + logging: ^1.2.0 + meta: ^1.9.1 dev_dependencies: - build_runner: ^2.0.0 - build_test: ^2.0.0 + build_runner: ^2.4.6 + build_test: ^2.2.0 build_verify: ^3.1.0 - collection: ^1.16.0 - coverage: ^1.0.2 - dart_code_metrics: '>=4.8.1 <6.0.0' + collection: ^1.18.0 + coverage: ^1.6.3 data_fixture_dart: ^2.2.0 faker: ^2.1.0 - http_parser: ^4.0.0 - lints: ^2.0.0 - test: ^1.16.4 - transparent_image: ^2.0.0 + http_parser: ^4.0.2 + lints: ^2.1.1 + test: ^1.24.4 + transparent_image: ^2.0.1 chopper_generator: path: ../chopper_generator diff --git a/chopper/test/fixtures/http_response_fixture.dart b/chopper/test/fixtures/http_response_fixture.dart index 6b6b6071..96292abd 100644 --- a/chopper/test/fixtures/http_response_fixture.dart +++ b/chopper/test/fixtures/http_response_fixture.dart @@ -12,7 +12,7 @@ extension ResponseFixture on http.Response { } @internal -class ResponseFactory extends FixtureFactory { +final class ResponseFactory extends FixtureFactory { @override FixtureDefinition definition() => define( (Faker faker) => http.Response( diff --git a/chopper/test/fixtures/payload_fixture.dart b/chopper/test/fixtures/payload_fixture.dart index 435883cf..c7a5fb24 100644 --- a/chopper/test/fixtures/payload_fixture.dart +++ b/chopper/test/fixtures/payload_fixture.dart @@ -8,7 +8,7 @@ extension PayloadFixture on Payload { } @internal -class PayloadFactory extends FixtureFactory { +final class PayloadFactory extends FixtureFactory { @override FixtureDefinition definition() => define( (Faker faker) => Payload( diff --git a/chopper/test/fixtures/request_fixture.dart b/chopper/test/fixtures/request_fixture.dart index 6d422cf4..073488ef 100644 --- a/chopper/test/fixtures/request_fixture.dart +++ b/chopper/test/fixtures/request_fixture.dart @@ -9,7 +9,7 @@ extension RequestFixture on Request { } @internal -class RequestFixtureFactory extends FixtureFactory { +final class RequestFixtureFactory extends FixtureFactory { @override FixtureDefinition definition() { final String method = diff --git a/chopper/test/fixtures/response_fixture.dart b/chopper/test/fixtures/response_fixture.dart index cd604e4f..f894c77e 100644 --- a/chopper/test/fixtures/response_fixture.dart +++ b/chopper/test/fixtures/response_fixture.dart @@ -10,7 +10,7 @@ extension ResponseFixture on Response { } @internal -class ResponseFixtureFactory extends FixtureFactory> { +final class ResponseFixtureFactory extends FixtureFactory> { @override FixtureDefinition> definition() { final http.Response base = diff --git a/chopper/test/helpers/payload.dart b/chopper/test/helpers/payload.dart index 4c4ea8a3..6403f7e3 100644 --- a/chopper/test/helpers/payload.dart +++ b/chopper/test/helpers/payload.dart @@ -1,6 +1,6 @@ import 'package:equatable/equatable.dart'; -class Payload with EquatableMixin { +final class Payload with EquatableMixin { const Payload({ this.statusCode = 200, this.message = 'OK', diff --git a/chopper_built_value/CHANGELOG.md b/chopper_built_value/CHANGELOG.md index 5fc1f1f7..7e536f4d 100644 --- a/chopper_built_value/CHANGELOG.md +++ b/chopper_built_value/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.0.0 + +- Require Dart 3.0 or later + ## 1.2.2 - Update http constraint to ">=0.13.0 <2.0.0" ([#431](https://github.com/lejard-h/chopper/pull/431)) diff --git a/chopper_built_value/analysis_options.yaml b/chopper_built_value/analysis_options.yaml index 7f5a674f..6f56a451 100644 --- a/chopper_built_value/analysis_options.yaml +++ b/chopper_built_value/analysis_options.yaml @@ -6,27 +6,6 @@ analyzer: - "**.chopper.dart" - "**.mocks.dart" - "example/**" - plugins: - - dart_code_metrics - -dart_code_metrics: - metrics: - cyclomatic-complexity: 20 - number-of-arguments: 4 - maximum-nesting-level: 5 - number-of-parameters: 7 - metrics-exclude: - - test/** - rules: - - newline-before-return - - no-boolean-literal-compare - - no-empty-block - - prefer-trailing-comma - - prefer-conditional-expressions - - no-equal-then-else - anti-patterns: - - long-method - - long-parameter-list linter: rules: diff --git a/chopper_built_value/pubspec.yaml b/chopper_built_value/pubspec.yaml index 1eed9725..a59baadb 100644 --- a/chopper_built_value/pubspec.yaml +++ b/chopper_built_value/pubspec.yaml @@ -1,25 +1,24 @@ name: chopper_built_value description: A built_value based Converter for Chopper. -version: 1.2.2 +version: 2.0.0 documentation: https://hadrien-lejard.gitbook.io/chopper/converters/built-value-converter repository: https://github.com/lejard-h/chopper environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: - built_value: ^8.0.0 - built_collection: ^5.0.0 - chopper: ^6.0.0 - http: ">=0.13.0 <2.0.0" + built_value: ^8.6.1 + built_collection: ^5.1.1 + chopper: ^7.0.0 + http: ^1.1.0 dev_dependencies: - test: ^1.16.4 - build_runner: ^2.0.0 - build_test: ^2.0.0 - built_value_generator: ^8.0.6 - dart_code_metrics: '>=4.8.1 <6.0.0' - lints: ^2.0.0 + test: ^1.24.4 + build_runner: ^2.4.6 + build_test: ^2.2.0 + built_value_generator: ^8.6.1 + lints: ^2.1.1 dependency_overrides: # Comment before publish diff --git a/chopper_generator/CHANGELOG.md b/chopper_generator/CHANGELOG.md index 36c3e7ca..d7b19300 100644 --- a/chopper_generator/CHANGELOG.md +++ b/chopper_generator/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 7.0.0 + +- Require Dart 3.0 or later +- Add final modifier to some classes ([#453](https://github.com/lejard-h/chopper/pull/453)) +- Replace deprecated Element.enclosingElement3 with Element.enclosingElement + ## 6.0.3 - Simplify library export diff --git a/chopper_generator/analysis_options.yaml b/chopper_generator/analysis_options.yaml index 2caa0f09..6f56a451 100644 --- a/chopper_generator/analysis_options.yaml +++ b/chopper_generator/analysis_options.yaml @@ -6,28 +6,6 @@ analyzer: - "**.chopper.dart" - "**.mocks.dart" - "example/**" - plugins: - - dart_code_metrics - -dart_code_metrics: - metrics: - cyclomatic-complexity: 20 - number-of-arguments: 4 - maximum-nesting-level: 5 - number-of-parameters: 10 - source-lines-of-code: 250 - metrics-exclude: - - test/** - rules: - - newline-before-return - - no-boolean-literal-compare - - no-empty-block - - prefer-trailing-comma - - prefer-conditional-expressions - - no-equal-then-else - anti-patterns: - - long-method - - long-parameter-list linter: rules: diff --git a/chopper_generator/lib/src/generator.dart b/chopper_generator/lib/src/generator.dart index 39353006..f91820f7 100644 --- a/chopper_generator/lib/src/generator.dart +++ b/chopper_generator/lib/src/generator.dart @@ -15,7 +15,8 @@ import 'package:logging/logging.dart'; import 'package:source_gen/source_gen.dart'; /// Code generator for [chopper.ChopperApi] annotated classes. -class ChopperGenerator extends GeneratorForAnnotation { +final class ChopperGenerator + extends GeneratorForAnnotation { const ChopperGenerator(); static final Logger _logger = Logger('Chopper Generator'); @@ -376,13 +377,11 @@ class ChopperGenerator extends GeneratorForAnnotation { }); } - /// TODO: Upgrade to `Element.enclosingElement` when analyzer 6.0.0 is released; in the mean time ignore the deprecation warning - /// https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/CHANGELOG.md#520 static String _factoryForFunction(FunctionTypedElement function) => // ignore: deprecated_member_use - function.enclosingElement3 is ClassElement + function.enclosingElement is ClassElement // ignore: deprecated_member_use - ? '${function.enclosingElement3!.name}.${function.name}' + ? '${function.enclosingElement!.name}.${function.name}' : function.name!; static Map _getAnnotation( diff --git a/chopper_generator/lib/src/utils.dart b/chopper_generator/lib/src/utils.dart index f1be6482..315238ed 100644 --- a/chopper_generator/lib/src/utils.dart +++ b/chopper_generator/lib/src/utils.dart @@ -3,7 +3,7 @@ import 'package:chopper_generator/src/extensions.dart'; import 'package:code_builder/code_builder.dart'; import 'package:source_gen/source_gen.dart'; -class Utils { +final class Utils { static bool getMethodOptionalBody(ConstantReader method) => method.read('optionalBody').boolValue; diff --git a/chopper_generator/pubspec.yaml b/chopper_generator/pubspec.yaml index fc438eca..e342ecc7 100644 --- a/chopper_generator/pubspec.yaml +++ b/chopper_generator/pubspec.yaml @@ -1,30 +1,29 @@ name: chopper_generator description: Chopper is an http client generator using source_gen, inspired by Retrofit -version: 6.0.3 +version: 7.0.0 documentation: https://hadrien-lejard.gitbook.io/chopper repository: https://github.com/lejard-h/chopper environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: - analyzer: '>=4.4.0 <6.0.0' - build: ^2.0.0 - built_collection: ^5.0.0 - chopper: ^6.0.0 - code_builder: ^4.3.0 - dart_style: ^2.0.0 - logging: ^1.0.0 - meta: ^1.3.0 - source_gen: ^1.0.0 + analyzer: ^5.13.0 + build: ^2.4.1 + built_collection: ^5.1.1 + chopper: ^7.0.0 + code_builder: ^4.5.0 + dart_style: ^2.3.2 + logging: ^1.2.0 + meta: ^1.9.1 + source_gen: ^1.4.0 dev_dependencies: - build_runner: ^2.0.0 + build_runner: ^2.4.6 build_verify: ^3.1.0 - dart_code_metrics: '>=4.8.1 <6.0.0' - http: ">=0.13.0 <2.0.0" - lints: ^2.0.0 - test: ^1.16.4 + http: ^1.1.0 + lints: ^2.1.1 + test: ^1.24.4 dependency_overrides: # Comment before publish diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index 7061686f..8ed20e77 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -5,26 +5,6 @@ analyzer: - "**.g.dart" - "**.chopper.dart" - "**.mocks.dart" - plugins: - - dart_code_metrics - -dart_code_metrics: - metrics: - cyclomatic-complexity: 20 - number-of-arguments: 4 - maximum-nesting-level: 5 - metrics-exclude: - - test/** - rules: - - newline-before-return - - no-boolean-literal-compare - - no-empty-block - - prefer-trailing-comma - - prefer-conditional-expressions - - no-equal-then-else - anti-patterns: - - long-method - - long-parameter-list linter: rules: diff --git a/example/lib/json_decode_service.activator.g.dart b/example/lib/json_decode_service.activator.g.dart index 1e151e3c..48ed6298 100644 --- a/example/lib/json_decode_service.activator.g.dart +++ b/example/lib/json_decode_service.activator.g.dart @@ -1,9 +1,10 @@ // GENERATED CODE - DO NOT MODIFY BY HAND // ************************************************************************** -// Generated by: WorkerGenerator +// Generator: WorkerGenerator 2.4.1 // ************************************************************************** import 'json_decode_service.vm.g.dart'; +/// Service activator for JsonDecodeService final $JsonDecodeServiceActivator = $getJsonDecodeServiceActivator(); diff --git a/example/lib/json_decode_service.dart b/example/lib/json_decode_service.dart index 41c94785..299b73c3 100644 --- a/example/lib/json_decode_service.dart +++ b/example/lib/json_decode_service.dart @@ -14,8 +14,7 @@ part 'json_decode_service.worker.g.dart'; // disable web to keep the number of generated files low for this example web: false, ) -class JsonDecodeService extends WorkerService - with $JsonDecodeServiceOperations { +class JsonDecodeService { @SquadronMethod() Future jsonDecode(String source) async => json.decode(source); } diff --git a/example/lib/json_decode_service.vm.g.dart b/example/lib/json_decode_service.vm.g.dart index 656bcef1..09d73096 100644 --- a/example/lib/json_decode_service.vm.g.dart +++ b/example/lib/json_decode_service.vm.g.dart @@ -1,13 +1,15 @@ // GENERATED CODE - DO NOT MODIFY BY HAND // ************************************************************************** -// Generated by: WorkerGenerator +// Generator: WorkerGenerator 2.4.1 // ************************************************************************** -import 'package:squadron/squadron_service.dart'; +import 'package:squadron/squadron.dart'; + import 'json_decode_service.dart'; -// VM entry point -void _start(List command) => run($JsonDecodeServiceInitializer, command, null); +/// VM entry point for JsonDecodeService +void _start$JsonDecodeService(List command) => + run($JsonDecodeServiceInitializer, command, null); -dynamic $getJsonDecodeServiceActivator() => _start; +EntryPoint $getJsonDecodeServiceActivator() => _start$JsonDecodeService; diff --git a/example/lib/json_decode_service.worker.g.dart b/example/lib/json_decode_service.worker.g.dart index 0cd306ce..18a33d72 100644 --- a/example/lib/json_decode_service.worker.g.dart +++ b/example/lib/json_decode_service.worker.g.dart @@ -3,53 +3,64 @@ part of 'json_decode_service.dart'; // ************************************************************************** -// WorkerGenerator +// Generator: WorkerGenerator 2.4.1 // ************************************************************************** -// Operations map for JsonDecodeService -mixin $JsonDecodeServiceOperations on WorkerService { +/// WorkerService class for JsonDecodeService +class _$JsonDecodeServiceWorkerService extends JsonDecodeService + implements WorkerService { + _$JsonDecodeServiceWorkerService() : super(); + @override - late final Map operations = - _getOperations(this as JsonDecodeService); + Map get operations => _operations; - static const int _$jsonDecodeId = 1; + late final Map _operations = { + _$jsonDecodeId: ($) => jsonDecode($.args[0]) + }; - static Map _getOperations(JsonDecodeService svc) => - {_$jsonDecodeId: (req) => svc.jsonDecode(req.args[0])}; + static const int _$jsonDecodeId = 1; } -// Service initializer -JsonDecodeService $JsonDecodeServiceInitializer(WorkerRequest startRequest) => - JsonDecodeService(); - -// Worker for JsonDecodeService -class _JsonDecodeServiceWorker extends Worker - with $JsonDecodeServiceOperations - implements JsonDecodeService { - _JsonDecodeServiceWorker() : super($JsonDecodeServiceActivator); +/// Service initializer for JsonDecodeService +WorkerService $JsonDecodeServiceInitializer(WorkerRequest startRequest) => + _$JsonDecodeServiceWorkerService(); +/// Operations map for JsonDecodeService +@Deprecated( + 'squadron_builder now supports "plain old Dart objects" as services. ' + 'Services do not need to derive from WorkerService nor do they need to mix in ' + 'with \$JsonDecodeServiceOperations anymore.') +mixin $JsonDecodeServiceOperations on WorkerService { @override - Future jsonDecode(String source) => send( - $JsonDecodeServiceOperations._$jsonDecodeId, - args: [source], - ); + // not needed anymore, generated for compatibility with previous versions of squadron_builder + Map get operations => WorkerService.noOperations; +} + +/// Worker for JsonDecodeService +class _$JsonDecodeServiceWorker extends Worker implements JsonDecodeService { + _$JsonDecodeServiceWorker({PlatformWorkerHook? platformWorkerHook}) + : super($JsonDecodeServiceActivator, + platformWorkerHook: platformWorkerHook); @override - Map get operations => WorkerService.noOperations; + Future jsonDecode(String source) => + send(_$JsonDecodeServiceWorkerService._$jsonDecodeId, args: [source]); final Object _detachToken = Object(); } -// Finalizable worker wrapper for JsonDecodeService -class JsonDecodeServiceWorker implements _JsonDecodeServiceWorker { - JsonDecodeServiceWorker() : _worker = _JsonDecodeServiceWorker() { - _finalizer.attach(this, _worker, detach: _worker._detachToken); +/// Finalizable worker wrapper for JsonDecodeService +class JsonDecodeServiceWorker implements _$JsonDecodeServiceWorker { + JsonDecodeServiceWorker({PlatformWorkerHook? platformWorkerHook}) + : _$w = + _$JsonDecodeServiceWorker(platformWorkerHook: platformWorkerHook) { + _finalizer.attach(this, _$w, detach: _$w._detachToken); } - final _JsonDecodeServiceWorker _worker; + final _$JsonDecodeServiceWorker _$w; - static final Finalizer<_JsonDecodeServiceWorker> _finalizer = - Finalizer<_JsonDecodeServiceWorker>((w) { + static final Finalizer<_$JsonDecodeServiceWorker> _finalizer = + Finalizer<_$JsonDecodeServiceWorker>((w) { try { _finalizer.detach(w._detachToken); w.stop(); @@ -59,52 +70,52 @@ class JsonDecodeServiceWorker implements _JsonDecodeServiceWorker { }); @override - Future jsonDecode(String source) => _worker.jsonDecode(source); + Future jsonDecode(String source) => _$w.jsonDecode(source); @override - Map get operations => _worker.operations; + List get args => _$w.args; @override - List get args => _worker.args; + Channel? get channel => _$w.channel; @override - Channel? get channel => _worker.channel; + Duration get idleTime => _$w.idleTime; @override - Duration get idleTime => _worker.idleTime; + bool get isStopped => _$w.isStopped; @override - bool get isStopped => _worker.isStopped; + int get maxWorkload => _$w.maxWorkload; @override - int get maxWorkload => _worker.maxWorkload; + WorkerStat get stats => _$w.stats; @override - WorkerStat get stats => _worker.stats; + String get status => _$w.status; @override - String get status => _worker.status; + int get totalErrors => _$w.totalErrors; @override - int get totalErrors => _worker.totalErrors; + int get totalWorkload => _$w.totalWorkload; @override - int get totalWorkload => _worker.totalWorkload; + Duration get upTime => _$w.upTime; @override - Duration get upTime => _worker.upTime; + String get workerId => _$w.workerId; @override - String get workerId => _worker.workerId; + int get workload => _$w.workload; @override - int get workload => _worker.workload; + PlatformWorkerHook? get platformWorkerHook => _$w.platformWorkerHook; @override - Future start() => _worker.start(); + Future start() => _$w.start(); @override - void stop() => _worker.stop(); + void stop() => _$w.stop(); @override Future send(int command, @@ -112,7 +123,7 @@ class JsonDecodeServiceWorker implements _JsonDecodeServiceWorker { CancellationToken? token, bool inspectRequest = false, bool inspectResponse = false}) => - _worker.send(command, + _$w.send(command, args: args, token: token, inspectRequest: inspectRequest, @@ -124,46 +135,52 @@ class JsonDecodeServiceWorker implements _JsonDecodeServiceWorker { CancellationToken? token, bool inspectRequest = false, bool inspectResponse = false}) => - _worker.stream(command, + _$w.stream(command, args: args, token: token, inspectRequest: inspectRequest, inspectResponse: inspectResponse); @override - Object get _detachToken => _worker._detachToken; + Object get _detachToken => _$w._detachToken; + + @override + Map get operations => WorkerService.noOperations; } -// Worker pool for JsonDecodeService -class _JsonDecodeServiceWorkerPool extends WorkerPool - with $JsonDecodeServiceOperations +/// Worker pool for JsonDecodeService +class _$JsonDecodeServiceWorkerPool extends WorkerPool implements JsonDecodeService { - _JsonDecodeServiceWorkerPool({ConcurrencySettings? concurrencySettings}) - : super(() => JsonDecodeServiceWorker(), + _$JsonDecodeServiceWorkerPool( + {ConcurrencySettings? concurrencySettings, + PlatformWorkerHook? platformWorkerHook}) + : super( + () => + JsonDecodeServiceWorker(platformWorkerHook: platformWorkerHook), concurrencySettings: concurrencySettings); @override Future jsonDecode(String source) => - execute(($w) => $w.jsonDecode(source)); - - @override - Map get operations => WorkerService.noOperations; + execute((w) => w.jsonDecode(source)); final Object _detachToken = Object(); } -// Finalizable worker pool wrapper for JsonDecodeService -class JsonDecodeServiceWorkerPool implements _JsonDecodeServiceWorkerPool { - JsonDecodeServiceWorkerPool({ConcurrencySettings? concurrencySettings}) - : _pool = _JsonDecodeServiceWorkerPool( - concurrencySettings: concurrencySettings) { - _finalizer.attach(this, _pool, detach: _pool._detachToken); +/// Finalizable worker pool wrapper for JsonDecodeService +class JsonDecodeServiceWorkerPool implements _$JsonDecodeServiceWorkerPool { + JsonDecodeServiceWorkerPool( + {ConcurrencySettings? concurrencySettings, + PlatformWorkerHook? platformWorkerHook}) + : _$p = _$JsonDecodeServiceWorkerPool( + concurrencySettings: concurrencySettings, + platformWorkerHook: platformWorkerHook) { + _finalizer.attach(this, _$p, detach: _$p._detachToken); } - final _JsonDecodeServiceWorkerPool _pool; + final _$JsonDecodeServiceWorkerPool _$p; - static final Finalizer<_JsonDecodeServiceWorkerPool> _finalizer = - Finalizer<_JsonDecodeServiceWorkerPool>((p) { + static final Finalizer<_$JsonDecodeServiceWorkerPool> _finalizer = + Finalizer<_$JsonDecodeServiceWorkerPool>((p) { try { _finalizer.detach(p._detachToken); p.stop(); @@ -173,101 +190,101 @@ class JsonDecodeServiceWorkerPool implements _JsonDecodeServiceWorkerPool { }); @override - Future jsonDecode(String source) => _pool.jsonDecode(source); + Future jsonDecode(String source) => _$p.jsonDecode(source); @override - Map get operations => _pool.operations; + ConcurrencySettings get concurrencySettings => _$p.concurrencySettings; @override - ConcurrencySettings get concurrencySettings => _pool.concurrencySettings; + Iterable get fullStats => _$p.fullStats; @override - Iterable get fullStats => _pool.fullStats; + int get maxConcurrency => _$p.maxConcurrency; @override - int get maxConcurrency => _pool.maxConcurrency; + int get maxParallel => _$p.maxParallel; @override - int get maxParallel => _pool.maxParallel; + int get maxSize => _$p.maxSize; @override - int get maxSize => _pool.maxSize; + int get maxWorkers => _$p.maxWorkers; @override - int get maxWorkers => _pool.maxWorkers; + int get maxWorkload => _$p.maxWorkload; @override - int get maxWorkload => _pool.maxWorkload; + int get minWorkers => _$p.minWorkers; @override - int get minWorkers => _pool.minWorkers; + int get pendingWorkload => _$p.pendingWorkload; @override - int get pendingWorkload => _pool.pendingWorkload; + int get size => _$p.size; @override - int get size => _pool.size; + Iterable get stats => _$p.stats; @override - Iterable get stats => _pool.stats; + bool get stopped => _$p.stopped; @override - bool get stopped => _pool.stopped; + int get totalErrors => _$p.totalErrors; @override - int get totalErrors => _pool.totalErrors; + int get totalWorkload => _$p.totalWorkload; @override - int get totalWorkload => _pool.totalWorkload; + int get workload => _$p.workload; @override - int get workload => _pool.workload; + void cancel([Task? task, String? message]) => _$p.cancel(task, message); @override - void cancel([Task? task, String? message]) => _pool.cancel(task, message); - - @override - FutureOr start() => _pool.start(); + FutureOr start() => _$p.start(); @override int stop([bool Function(JsonDecodeServiceWorker worker)? predicate]) => - _pool.stop(predicate); + _$p.stop(predicate); @override Object registerWorkerPoolListener( void Function(JsonDecodeServiceWorker worker, bool removed) listener) => - _pool.registerWorkerPoolListener(listener); + _$p.registerWorkerPoolListener(listener); @override void unregisterWorkerPoolListener( {void Function(JsonDecodeServiceWorker worker, bool removed)? listener, Object? token}) => - _pool.unregisterWorkerPoolListener(listener: listener, token: token); + _$p.unregisterWorkerPoolListener(listener: listener, token: token); @override Future execute(Future Function(JsonDecodeServiceWorker worker) task, {PerfCounter? counter}) => - _pool.execute(task, counter: counter); + _$p.execute(task, counter: counter); @override StreamTask scheduleStream( Stream Function(JsonDecodeServiceWorker worker) task, {PerfCounter? counter}) => - _pool.scheduleStream(task, counter: counter); + _$p.scheduleStream(task, counter: counter); @override ValueTask scheduleTask( Future Function(JsonDecodeServiceWorker worker) task, {PerfCounter? counter}) => - _pool.scheduleTask(task, counter: counter); + _$p.scheduleTask(task, counter: counter); @override Stream stream(Stream Function(JsonDecodeServiceWorker worker) task, {PerfCounter? counter}) => - _pool.stream(task, counter: counter); + _$p.stream(task, counter: counter); @override - Object get _detachToken => _pool._detachToken; + Object get _detachToken => _$p._detachToken; + + @override + Map get operations => WorkerService.noOperations; } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d88b0adf..735d046c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,25 +5,24 @@ documentation: https://hadrien-lejard.gitbook.io/chopper/ #author: Hadrien Lejard environment: - sdk: '>=2.17.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: chopper: - json_annotation: + json_annotation: ^4.8.1 built_value: - analyzer: - http: - built_collection: - squadron: ^5.0.0 + analyzer: ^5.13.0 + http: ^1.1.0 + built_collection: ^5.1.1 + squadron: ^5.1.3 dev_dependencies: - build_runner: + build_runner: ^2.4.6 chopper_generator: - json_serializable: - built_value_generator: - dart_code_metrics: '>=4.8.1 <6.0.0' - lints: ^2.0.0 - squadron_builder: ^2.1.2 + json_serializable: ^6.7.1 + built_value_generator: ^8.6.1 + lints: ^2.1.1 + squadron_builder: ^2.4.1 dependency_overrides: chopper: