Skip to content

Commit

Permalink
🔖 pre-release v8.0.0-rc.2 (#606)
Browse files Browse the repository at this point in the history
# chopper

## 8.0.0-rc.2

- #604

# chopper_generator

## 8.0.0-rc.2

- #604

# chopper_built_value

## 3.0.0-rc.1

- Require Chopper ^8.0.0

---------

Signed-off-by: dependabot[bot] <[email protected]>
  • Loading branch information
techouse authored May 3, 2024
1 parent ed2cee4 commit ae505af
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 23 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defaults:
shell: bash
env:
PUB_ENVIRONMENT: bot.github
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
permissions: read-all

jobs:
Expand Down Expand Up @@ -133,7 +134,7 @@ jobs:
if: "always() && steps.chopper_pub_upgrade.conclusion == 'success'"
working-directory: chopper
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: chopper/coverage/lcov.info
fail_ci_if_error: true
Expand All @@ -148,7 +149,7 @@ jobs:
if: "always() && steps.chopper_built_value_pub_upgrade.conclusion == 'success'"
working-directory: chopper_built_value
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: chopper_built_value/coverage/lcov.info
fail_ci_if_error: true
Expand All @@ -163,7 +164,7 @@ jobs:
if: "always() && steps.chopper_generator_pub_upgrade.conclusion == 'success'"
working-directory: chopper_generator
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: chopper_generator/coverage/lcov.info
fail_ci_if_error: true
Expand Down
4 changes: 4 additions & 0 deletions chopper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.0.0-rc.2

- Add per-request timeout ([#604](https://github.com/lejard-h/chopper/pull/604))

## 8.0.0-rc.1

- Restructure interceptors ([#547](https://github.com/lejard-h/chopper/pull/547))
Expand Down
11 changes: 11 additions & 0 deletions chopper/lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ sealed class Method {
/// The above code produces hxxp://path/to/script&foo=foo_var&bar=&baz=baz_var
final bool? includeNullQueryVars;

/// Set a timeout for the request
final Duration? timeout;

/// {@macro Method}
const Method(
this.method, {
Expand All @@ -244,6 +247,7 @@ sealed class Method {
this.listFormat,
@Deprecated('Use listFormat instead') this.useBrackets,
this.includeNullQueryVars,
this.timeout,
});
}

Expand All @@ -261,6 +265,7 @@ final class Get extends Method {
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Get);
}

Expand All @@ -280,6 +285,7 @@ final class Post extends Method {
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Post);
}

Expand All @@ -297,6 +303,7 @@ final class Delete extends Method {
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Delete);
}

Expand All @@ -316,6 +323,7 @@ final class Put extends Method {
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Put);
}

Expand All @@ -334,6 +342,7 @@ final class Patch extends Method {
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Patch);
}

Expand All @@ -351,6 +360,7 @@ final class Head extends Method {
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Head);
}

Expand All @@ -368,6 +378,7 @@ final class Options extends Method {
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Options);
}

Expand Down
8 changes: 4 additions & 4 deletions chopper/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: chopper
description: Chopper is an http client generator using source_gen, inspired by Retrofit
version: 8.0.0-rc.1
version: 8.0.0-rc.2
documentation: https://hadrien-lejard.gitbook.io/chopper
repository: https://github.com/lejard-h/chopper

Expand All @@ -12,7 +12,7 @@ dependencies:
http: ^1.1.0
logging: ^1.2.0
meta: ^1.9.1
qs_dart: ^1.0.4
qs_dart: ^1.0.10

dev_dependencies:
build_runner: ^2.4.9
Expand All @@ -24,9 +24,9 @@ dev_dependencies:
faker: ^2.1.0
http_parser: ^4.0.2
lints: ^3.0.0
test: ^1.25.2
test: ^1.25.4
transparent_image: ^2.0.1
#chopper_generator: ^8.0.0 # commented out for publishing rc to pub.dev
chopper_generator: ">=8.0.0-rc.1 <9.0.0" # Will be replaced with ^8.0.0 once released

dependency_overrides:
chopper_generator:
Expand Down
46 changes: 46 additions & 0 deletions chopper/test/chain/interceptor_chain_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:chopper/src/chain/chain.dart';
import 'package:chopper/src/chain/interceptor_chain.dart';
import 'package:chopper/src/interceptors/interceptor.dart';
import 'package:chopper/src/interceptors/internal_interceptor.dart';
import 'package:chopper/src/interceptors/request_converter_interceptor.dart';
import 'package:chopper/src/interceptors/response_converter_interceptor.dart';
import 'package:chopper/src/request.dart';
import 'package:chopper/src/response.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -153,6 +155,50 @@ void main() {
);
});
});

group('Chain exception tests', () {
late Request mockRequest;
late InterceptorChain interceptorChain;
setUp(() {
mockRequest = Request(
'GET',
Uri.parse('bar'),
Uri.parse('http://localhost'),
body: 'Test',
);
});

test('Exception thrown inside the interceptor chain will be passed up',
() async {
interceptorChain = InterceptorChain(
interceptors: [
RequestConverterInterceptor(null, null),
PassthroughInterceptor(),
PassthroughInterceptor(),
ResponseConverterInterceptor(
converter: null,
errorConverter: null,
responseConverter: null,
),
ExceptionThrowingInterceptor(),
],
request: mockRequest,
);

expect(
() => interceptorChain.proceed(mockRequest),
throwsA(isA<Exception>().having(
(e) => e.toString(), 'message', 'Exception: Test exception')),
);
});
});
}

class ExceptionThrowingInterceptor implements Interceptor {
@override
FutureOr<Response<BodyType>> intercept<BodyType>(Chain<BodyType> chain) {
throw Exception('Test exception');
}
}

class RequestModifierInterceptor implements Interceptor {
Expand Down
39 changes: 39 additions & 0 deletions chopper/test/test_service.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions chopper/test/test_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ abstract class HttpTestService extends ChopperService {
@Field() final List<int> positives, [
@Field() final String? signature,
]);

@Get(path: 'get_timeout', timeout: Duration(seconds: 42))
Future<Response<String>> getTimeoutTest();

@Get(path: 'get_timeout_zero', timeout: Duration(seconds: 0))
Future<Response<String>> getTimeoutTestZero();

@Get(path: 'get_timeout_neg', timeout: Duration(seconds: -1))
Future<Response<String>> getTimeoutTestNeg();
}

Request customConvertRequest(Request req) {
Expand Down
4 changes: 4 additions & 0 deletions chopper_built_value/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.0.0-rc.1

- Require Chopper ^8.0.0

## 2.0.1+2

- Fix Github release workflow permissions ([#512](https://github.com/lejard-h/chopper/pull/512))
Expand Down
20 changes: 10 additions & 10 deletions chopper_built_value/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: chopper_built_value
description: A built_value based Converter for Chopper.
version: 2.0.1+2
version: 3.0.0-rc.1
documentation: https://hadrien-lejard.gitbook.io/chopper/converters/built-value-converter
repository: https://github.com/lejard-h/chopper

environment:
sdk: ">=3.0.0 <4.0.0"
sdk: ^3.0.0

dependencies:
built_value: ^8.6.1
built_value: ^8.9.2
built_collection: ^5.1.1
chopper: ^7.0.0
chopper: ">=8.0.0-rc.1 <9.0.0"
http: ^1.1.0

dev_dependencies:
test: ^1.24.4
build_runner: ^2.4.6
build_test: ^2.2.0
built_value_generator: ^8.6.1
lints: ">=2.1.1 <4.0.0"
test: ^1.25.4
build_runner: ^2.4.9
build_test: ^2.2.2
built_value_generator: ^8.9.2
lints: ^3.0.0

dependency_overrides:
chopper:
Expand All @@ -27,4 +27,4 @@ dependency_overrides:
topics:
- codegen
- converter
- built-value
- built-value
4 changes: 4 additions & 0 deletions chopper_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.0.0-rc.2

- Add per-request timeout ([#604](https://github.com/lejard-h/chopper/pull/604))

## 8.0.0-rc.1

- Restructure interceptors ([#547](https://github.com/lejard-h/chopper/pull/547))
Expand Down
11 changes: 10 additions & 1 deletion chopper_generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ final class ChopperGenerator

final bool? includeNullQueryVars = Utils.getIncludeNullQueryVars(method);

final Duration? timeout = Utils.getTimeout(method);

blocks.add(
declareFinal(Vars.request.toString(), type: refer('Request'))
.assign(
Expand Down Expand Up @@ -454,12 +456,19 @@ final class ChopperGenerator
]);
}

final returnStatement =
Expression returnStatement =
refer(Vars.client.toString()).property('send').call(
[refer(Vars.request.toString())],
namedArguments,
typeArguments,
);
if (timeout != null) {
returnStatement = returnStatement.property('timeout').call([
refer('Duration').constInstance([], {
'microseconds': literalNum(timeout.inMicroseconds),
}),
]);
}

if (isResponseObject) {
// Return the response object directly from chopper.send
Expand Down
15 changes: 15 additions & 0 deletions chopper_generator/lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math' show max;

import 'package:analyzer/dart/element/element.dart';
import 'package:chopper_generator/src/extensions.dart';
import 'package:code_builder/code_builder.dart';
Expand Down Expand Up @@ -33,6 +35,19 @@ final class Utils {
static bool? getIncludeNullQueryVars(ConstantReader method) =>
method.peek('includeNullQueryVars')?.boolValue;

static Duration? getTimeout(ConstantReader method) {
final ConstantReader? timeout = method.peek('timeout');
if (timeout != null) {
final int? microseconds =
timeout.objectValue.getField('_duration')?.toIntValue();
if (microseconds != null) {
return Duration(microseconds: max(microseconds, 0));
}
}

return null;
}

/// All positional required params must support nullability
static Parameter buildRequiredPositionalParam(ParameterElement p) =>
Parameter(
Expand Down
Loading

0 comments on commit ae505af

Please sign in to comment.