Skip to content

v5.1.0 #125

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

Merged
merged 3 commits into from
May 13, 2022
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
6 changes: 3 additions & 3 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
runs-on: ubuntu-latest

container:
image: google/dart:latest
image: dart:stable

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: dart pub get
- name: Format
run: dartfmt --dry-run --set-exit-if-changed lib test
run: dart format --output none --set-exit-if-changed example lib test
- name: Analyzer
run: dart analyze --fatal-infos --fatal-warnings
- name: Tests
run: dart test --coverage=.coverage -j1
- name: Coverage
run: dart run coverage:format_coverage -l -c -i .coverage --report-on=lib --packages=.packages | dart run check_coverage:check_coverage
run: dart run coverage:format_coverage -l -c -i .coverage --report-on=lib | dart run check_coverage:check_coverage
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.1.0] - 2022-05-11
### Changed
- Dependency versions bump
- Minor formatting improvements

## [5.0.5] - 2021-07-19
### Fixed
- Pagination with null values crashes json parser (#123)
Expand Down Expand Up @@ -208,6 +213,7 @@ the Document model.
### Added
- Client: fetch resources, collections, related resources and relationships

[5.1.0]: https://github.com/f3ath/json-api-dart/compare/5.0.5...5.1.0
[5.0.5]: https://github.com/f3ath/json-api-dart/compare/5.0.4...5.0.5
[5.0.4]: https://github.com/f3ath/json-api-dart/compare/5.0.3...5.0.4
[5.0.3]: https://github.com/f3ath/json-api-dart/compare/5.0.2...5.0.3
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml
linter:
rules:
- sort_constructors_first
Expand Down
4 changes: 3 additions & 1 deletion example/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void main() async {
});
} on RequestFailure catch (e) {
/// Catch error response
e.errors.forEach((error) => print('${error.title}'));
for (var error in e.errors) {
print(error.title);
}
}
}
4 changes: 2 additions & 2 deletions example/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Future<void> main() async {

print('The server is listening at $host:$port.'
' Try opening the following URL(s) in your browser:');
resources.forEach((resource) {
for (var resource in resources) {
print('http://$host:$port/$resource');
});
}
}

Future addColors(Repository repo) async {
Expand Down
6 changes: 3 additions & 3 deletions example/server/in_memory_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'repository.dart';

class InMemoryRepo implements Repository {
InMemoryRepo(Iterable<String> types) {
types.forEach((_) {
_storage[_] = {};
});
for (var type in types) {
_storage[type] = {};
}
}

final _storage = <String, Map<String, Model>>{};
Expand Down
1 change: 1 addition & 0 deletions lib/src/client/response/resource_updated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ResourceUpdated {
return doc.dataAsResource();
}
}
return null;
}

final HttpResponse http;
Expand Down
16 changes: 11 additions & 5 deletions lib/src/client/routing_client.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:json_api/client.dart';
import 'package:json_api/document.dart';
import 'package:json_api/routing.dart';
import 'package:json_api/src/client/client.dart';
Expand All @@ -8,6 +7,7 @@ import 'package:json_api/src/client/response/collection_fetched.dart';
import 'package:json_api/src/client/response/related_resource_fetched.dart';
import 'package:json_api/src/client/response/relationship_fetched.dart';
import 'package:json_api/src/client/response/relationship_updated.dart';
import 'package:json_api/src/client/response/request_failure.dart';
import 'package:json_api/src/client/response/resource_created.dart';
import 'package:json_api/src/client/response/resource_fetched.dart';
import 'package:json_api/src/client/response/resource_updated.dart';
Expand Down Expand Up @@ -176,8 +176,11 @@ class RoutingClient {
Map<String, String> headers = const {},
Map<String, String> query = const {},
}) async {
final response = await send(baseUri.relationship(type, id, relationship),
Request.get()..headers.addAll(headers)..query.addAll(query));
final response = await send(
baseUri.relationship(type, id, relationship),
Request.get()
..headers.addAll(headers)
..query.addAll(query));
return RelationshipFetched.one(
response.http, response.document ?? (throw FormatException()));
}
Expand All @@ -189,8 +192,11 @@ class RoutingClient {
Map<String, String> headers = const {},
Map<String, String> query = const {},
}) async {
final response = await send(baseUri.relationship(type, id, relationship),
Request.get()..headers.addAll(headers)..query.addAll(query));
final response = await send(
baseUri.relationship(type, id, relationship),
Request.get()
..headers.addAll(headers)
..query.addAll(query));
return RelationshipFetched.many(
response.http, response.document ?? (throw FormatException()));
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/document/inbound_document.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:json_api/document.dart';
import 'package:json_api/src/document/error_object.dart';
import 'package:json_api/src/document/error_source.dart';
import 'package:json_api/src/document/identifier.dart';
Expand Down
11 changes: 6 additions & 5 deletions lib/src/document/many.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:json_api/document.dart';
import 'package:json_api/src/document/identifier.dart';
import 'package:json_api/src/document/relationship.dart';
import 'package:json_api/src/document/resource.dart';
import 'package:json_api/src/document/resource_collection.dart';

class ToMany extends Relationship {
ToMany(Iterable<Identifier> identifiers) {
identifiers.forEach((_) => _map[_.key] = _);
for (var id in identifiers) {
_map[id.key] = id;
}
}

final _map = <String, Identifier>{};
Expand All @@ -20,7 +22,6 @@ class ToMany extends Relationship {
/// Finds the referenced elements which are found in the [collection].
/// The resulting [Iterable] may contain fewer elements than referred by the
/// relationship if the [collection] does not have all of them.
Iterable<Resource> findIn(ResourceCollection collection) {
return _map.keys.map((key) => collection[key]).whereType();
}
Iterable<Resource> findIn(ResourceCollection collection) =>
_map.keys.map((key) => collection[key]).whereType();
}
5 changes: 4 additions & 1 deletion lib/src/document/outbound_document.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:json_api/document.dart';
import 'package:json_api/src/document/error_object.dart';
import 'package:json_api/src/document/link.dart';
import 'package:json_api/src/document/many.dart';
import 'package:json_api/src/document/new_resource.dart';
import 'package:json_api/src/document/one.dart';
import 'package:json_api/src/document/resource.dart';

/// A sever-to-client document.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/document/relationship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:collection';
import 'package:json_api/src/document/identifier.dart';
import 'package:json_api/src/document/link.dart';

class Relationship with IterableMixin<Identifier /*!*/ > {
class Relationship with IterableMixin<Identifier> {
final links = <String, Link>{};
final meta = <String, Object?>{};

Expand Down
1 change: 1 addition & 0 deletions lib/src/document/resource_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ mixin ResourceProperties {
R? _rel<R extends Relationship>(String name) {
final r = relationships[name];
if (r is R) return r;
return null;
}
}
2 changes: 1 addition & 1 deletion lib/src/query/filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Filter with MapMixin<String, String> {

static Filter fromUri(Uri uri) => Filter(uri.queryParametersAll
.map((k, v) => MapEntry(_regex.firstMatch(k)?.group(1) ?? '', v.last))
..removeWhere((k, v) => k.isEmpty));
..removeWhere((k, v) => k.isEmpty));

static final _regex = RegExp(r'^filter\[(.+)\]$');

Expand Down
2 changes: 1 addition & 1 deletion lib/src/query/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Page with MapMixin<String, String> {

static Page fromUri(Uri uri) => Page(uri.queryParametersAll
.map((k, v) => MapEntry(_regex.firstMatch(k)?.group(1) ?? '', v.last))
..removeWhere((k, v) => k.isEmpty));
..removeWhere((k, v) => k.isEmpty));
static final _regex = RegExp(r'^page\[(.+)\]$');

final _ = <String, String>{};
Expand Down
14 changes: 7 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: json_api
version: 5.0.5
version: 5.1.0
homepage: https://github.com/f3ath/json-api-dart
description: A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dependencies:
http: ^0.13.0
http: ^0.13.4
http_parser: ^4.0.0

dev_dependencies:
pedantic: ^1.10.0
test: ^1.16.0
lints: ^1.0.1
test: ^1.21.1
stream_channel: ^2.1.0
uuid: ^3.0.0
coverage: ^1.0.2
check_coverage: ^0.0.2
coverage: ^1.3.0
check_coverage: ^0.0.4

cider:
link_template:
Expand Down
1 change: 0 additions & 1 deletion test/unit/client/response.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:convert';

import 'package:json_api/http.dart';
import 'package:json_api/src/http/media_type.dart';

final collectionMin = HttpResponse(200,
body: jsonEncode({
Expand Down
4 changes: 2 additions & 2 deletions test/unit/http/encoding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main() {
final stringBodyEn = 'qwerty';
final bytesBodyEn = utf8.encode(stringBodyEn);

final buildResponse = (
buildResponse(
List<int> bytesBody,
Encoding encoding,
) async {
Expand All @@ -27,7 +27,7 @@ void main() {
);

return dartHttp.handle(HttpRequest('get', Uri.parse('http://test.com')));
};
}

test('UTF-8 ru', () async {
final response = await buildResponse(bytesBodyRu, utf8);
Expand Down