Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #83 from dart-lang/prep_publish
Browse files Browse the repository at this point in the history
prep for publishing 3.0.2
  • Loading branch information
devoncarew authored Jun 15, 2022
2 parents 2de9a1f + 1b3e473 commit 4b0806f
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [2.12.0, dev]
sdk: [2.15.0, dev]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1.0
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 3.0.2-dev
## 3.0.2

* Switch to using `package:lints`.
* Address a few analysis hint violations.
* Populate the pubspec `repository` field.

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Dart CI](https://github.com/dart-lang/json_rpc_2/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/json_rpc_2/actions/workflows/test-package.yml)
[![pub package](https://img.shields.io/pub/v/json_rpc_2.svg)](https://pub.dev/packages/json_rpc_2)
[![package publisher](https://img.shields.io/pub/publisher/json_rpc_2.svg)](https://pub.dev/packages/json_rpc_2/publisher)

A library that implements the [JSON-RPC 2.0 spec][spec].

[spec]: https://www.jsonrpc.org/specification
Expand Down
18 changes: 14 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

linter:
rules:
- always_declare_return_types
# - avoid_dynamic_calls
- avoid_unused_constructor_parameters
- cancel_subscriptions
- directives_ordering
- omit_local_variable_types
- package_api_docs
- prefer_single_quotes
- test_types_in_equals
- throw_in_finally
- unawaited_futures
3 changes: 2 additions & 1 deletion example/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:json_rpc_2/json_rpc_2.dart';
import 'package:pedantic/pedantic.dart';
import 'package:web_socket_channel/web_socket_channel.dart';

void main() async {
Expand Down
2 changes: 2 additions & 0 deletions lib/error_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: constant_identifier_names

/// Error codes defined in the [JSON-RPC 2.0 specificiation][spec].
///
/// These codes are generally used for protocol-level communication. Most of
Expand Down
5 changes: 4 additions & 1 deletion lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ class Client {
/// invokes [callback] without creating another batch. This means that
/// responses are batched until the first batch ends.
void withBatch(Function() callback) {
if (_batch != null) return callback();
if (_batch != null) {
callback();
return;
}

_batch = [];
return tryFinally(callback, () {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RpcException implements Exception {
/// This must be a JSON-serializable object. If it's a [Map] without a
/// `"request"` key, a copy of the request that caused the error will
/// automatically be injected.
final data;
final Object? data;

RpcException(this.code, this.message, {this.data});

Expand All @@ -44,9 +44,9 @@ class RpcException implements Exception {
/// Converts this exception into a JSON-serializable object that's a valid
/// JSON-RPC 2.0 error response.
Map<String, dynamic> serialize(request) {
var modifiedData;
if (data is Map && !data.containsKey('request')) {
modifiedData = Map.from(data);
dynamic modifiedData;
if (data is Map && !(data as Map).containsKey('request')) {
modifiedData = Map.from(data as Map);
modifiedData['request'] = request;
} else if (data == null) {
modifiedData = {'request': request};
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Parameters {
/// If this is accessed for a [Parameter] that was not passed, the request
/// will be automatically rejected. To avoid this, use [Parameter.valueOr].
dynamic get value => _value;
final _value;
final dynamic _value;

Parameters(this.method, this._value);

Expand Down Expand Up @@ -111,7 +111,7 @@ class Parameter extends Parameters {
final Parameters _parent;

/// The key used to access [this], used to construct [_path].
final _key;
final dynamic _key;

/// A human-readable representation of the path of getters used to get this.
///
Expand Down
8 changes: 4 additions & 4 deletions lib/src/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Server {
/// if no response should be sent. [callback] may send custom
/// errors by throwing an [RpcException].
Future _handleRequest(request) async {
var response;
dynamic response;
if (request is List) {
if (request.isEmpty) {
response = RpcException(error_code.INVALID_REQUEST,
Expand Down Expand Up @@ -301,7 +301,7 @@ class Server {
Future _tryFallbacks(Parameters params) {
var iterator = _fallbacks.toList().iterator;

Future _tryNext() async {
Future tryNext() async {
if (!iterator.moveNext()) {
throw RpcException.methodNotFound(params.method);
}
Expand All @@ -310,10 +310,10 @@ class Server {
return await iterator.current(params);
} on RpcException catch (error) {
if (error.code != error_code.METHOD_NOT_FOUND) rethrow;
return _tryNext();
return tryNext();
}
}

return _tryNext();
return tryNext();
}
}
3 changes: 1 addition & 2 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ String getErrorMessage(error) =>
/// This is synchronicity-agnostic relative to [body]. If [body] returns a
/// [Future], this wil run asynchronously; otherwise it will run synchronously.
void tryFinally(Function() body, Function() whenComplete) {
var result;
dynamic result;
try {
result = body();
} catch (_) {
Expand All @@ -38,7 +38,6 @@ void tryFinally(Function() body, Function() whenComplete) {

if (result is! Future) {
whenComplete();
return result;
} else {
result.whenComplete(whenComplete);
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_rpc_2
version: 3.0.2-dev
version: 3.0.2
description: >-
Utilities to write a client or server using the JSON-RPC 2.0 spec.
repository: https://github.com/dart-lang/json_rpc_2
Expand All @@ -12,6 +12,6 @@ dependencies:
stream_channel: ^2.1.0

dev_dependencies:
pedantic: ^1.11.0
lints: '>=1.0.0 < 3.0.0'
test: ^1.16.0
web_socket_channel: ^2.0.0
5 changes: 3 additions & 2 deletions test/client/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';
import 'package:json_rpc_2/error_code.dart' as error_code;
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
import 'package:test/test.dart';

import 'utils.dart';

void main() {
var controller;
late ClientController controller;

setUp(() => controller = ClientController());

test('sends a message and returns the response', () {
Expand Down
10 changes: 5 additions & 5 deletions test/client/stream_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import 'dart:async';

import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';

import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;

void main() {
var responseController;
var requestController;
var client;
late StreamController responseController;
late StreamController requestController;
late json_rpc.Client client;

setUp(() {
responseController = StreamController();
requestController = StreamController();
Expand Down
3 changes: 1 addition & 2 deletions test/client/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import 'dart:async';
import 'dart:convert';

import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';

import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;

/// A controller used to test a [json_rpc.Client].
class ClientController {
/// The controller for the client's response stream.
Expand Down
14 changes: 7 additions & 7 deletions test/peer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import 'dart:async';
import 'dart:convert';

import 'package:pedantic/pedantic.dart';
import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';

import 'package:json_rpc_2/error_code.dart' as error_code;
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';

void main() {
var incoming;
var outgoing;
var peer;
late StreamSink incoming;
late Stream outgoing;
late json_rpc.Peer peer;

setUp(() {
var incomingController = StreamController();
incoming = incomingController.sink;
Expand Down Expand Up @@ -240,6 +239,7 @@ void main() {
);
peer
..registerMethod('foo', () => throw exception)
// ignore: unawaited_futures
..listen();

incomingController.add({'jsonrpc': '2.0', 'method': 'foo'});
Expand Down
5 changes: 3 additions & 2 deletions test/server/batch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';
import 'package:json_rpc_2/error_code.dart' as error_code;
import 'package:test/test.dart';

import 'utils.dart';

void main() {
var controller;
late ServerController controller;

setUp(() {
controller = ServerController();
controller.server
Expand Down
4 changes: 2 additions & 2 deletions test/server/invalid_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';
import 'package:json_rpc_2/error_code.dart' as error_code;
import 'package:test/test.dart';

import 'utils.dart';

void main() {
var controller;
late ServerController controller;
setUp(() => controller = ServerController());

test('a non-Array/Object request is invalid', () {
Expand Down
11 changes: 6 additions & 5 deletions test/server/parameters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
import 'package:test/test.dart';

import 'utils.dart';

void main() {
group('with named parameters', () {
var parameters;
late json_rpc.Parameters parameters;
setUp(() {
parameters = json_rpc.Parameters('foo', {
'num': 1.5,
Expand Down Expand Up @@ -277,7 +277,7 @@ void main() {
});

group('with a nested parameter map', () {
var nested;
late json_rpc.Parameter nested;
setUp(() => nested = parameters['map']);

test('[int] fails with a type error', () {
Expand Down Expand Up @@ -312,7 +312,8 @@ void main() {
});

group('with a nested parameter list', () {
var nested;
late json_rpc.Parameter nested;

setUp(() => nested = parameters['list']);

test('[string] fails with a type error', () {
Expand Down Expand Up @@ -348,7 +349,7 @@ void main() {
});

group('with positional parameters', () {
var parameters;
late json_rpc.Parameters parameters;
setUp(() => parameters = json_rpc.Parameters('foo', [1, 2, 3, 4, 5]));

test('value returns the wrapped value', () {
Expand Down
5 changes: 3 additions & 2 deletions test/server/server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

import 'dart:convert';

import 'package:test/test.dart';
import 'package:json_rpc_2/error_code.dart' as error_code;
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
import 'package:test/test.dart';

import 'utils.dart';

void main() {
var controller;
late ServerController controller;

setUp(() => controller = ServerController());

test('calls a registered method with the given name', () {
Expand Down
10 changes: 5 additions & 5 deletions test/server/stream_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import 'dart:async';

import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';

import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;

void main() {
var requestController;
var responseController;
var server;
late StreamController requestController;
late StreamController responseController;
late json_rpc.Server server;

setUp(() {
requestController = StreamController();
responseController = StreamController();
Expand Down
Loading

0 comments on commit 4b0806f

Please sign in to comment.