Skip to content

Commit 903bb2b

Browse files
authored
v5 (#109)
1 parent 1e192c0 commit 903bb2b

File tree

172 files changed

+4606
-5864
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+4606
-5864
lines changed

.cider.yaml

-2
This file was deleted.

.github/workflows/dart.yml

+11-9
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ jobs:
1515
image: google/dart:latest
1616

1717
steps:
18-
- uses: actions/checkout@v2
19-
- name: Install dependencies
20-
run: pub get
21-
- name: Formatting
22-
run: dartfmt -n --set-exit-if-changed .
23-
- name: Analyzer
24-
run: dartanalyzer --fatal-infos --fatal-warnings lib test example
25-
- name: Run tests
26-
run: pub run test
18+
- uses: actions/checkout@v2
19+
- name: Install dependencies
20+
run: dart pub get
21+
- name: Format
22+
run: dartfmt --dry-run --set-exit-if-changed lib test
23+
- name: Analyzer
24+
run: dart analyze --fatal-infos --fatal-warnings
25+
- name: Tests
26+
run: dart test --coverage=.coverage -j1
27+
- name: Coverage
28+
run: dart run coverage:format_coverage -l -c -i .coverage --report-on=lib --packages=.packages | dart run check_coverage:check_coverage

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ pubspec.lock
1313
# If you don't generate documentation locally you can remove this line.
1414
doc/api/
1515

16-
# Generated by test_coverage
17-
test/.test_coverage.dart
18-
coverage
19-
coverage_badge.svg
16+
# Generated by coverage
17+
/.coverage/

.travis.yml

-11
This file was deleted.

CHANGELOG.md

+45-28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Sound null-safety support.
10+
11+
### Changed
12+
- Everything. Again. This is another major **BC-breaking** rework. Please refer to
13+
the API documentation, examples and tests.
14+
815
## [4.3.0] - 2020-07-30
916
### Added
1017
- `meta` parameter for createResourceAt()
@@ -26,24 +33,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2633
- Filtering support for collections ([pr](https://github.com/f3ath/json-api-dart/pull/97))
2734

2835
### Changed
29-
- The client will not attempt to decode the body of the HTTP response with error status if the correct Content-Type
30-
is missing. Before in such cases a `FormatException` would be thrown ([pr](https://github.com/f3ath/json-api-dart/pull/98))
36+
- The client will not attempt to decode the body of the HTTP response with error status if the correct Content-Type
37+
is missing. Before in such cases a `FormatException` would be thrown ([pr](https://github.com/f3ath/json-api-dart/pull/98))
3138

3239
## [4.1.0] - 2020-05-28
3340
### Changed
3441
- `DartHttp` now defaults to utf8 if no encoding is specified in the response.
3542

36-
## [4.0.0] - 2020-05-26
43+
## [4.0.0] - 2020-02-29
3744
### Changed
38-
- This is a major **BC-breaking** rework which affected pretty much all areas.
45+
- Everything. This is a major **BC-breaking** rework which affected pretty much all areas. Please refer to the documentation.
46+
47+
## [3.2.3] - 2020-08-06
48+
### Fixed
49+
- Call toJson() on resourceObject when serializing ([#84](https://github.com/f3ath/json-api-dart/pull/84))
50+
3951

4052
## [3.2.2] - 2020-01-07
4153
### Fixed
42-
- Can not decode related resource which is null ([issue](https://github.com/f3ath/json-api-dart/issues/77))
54+
- Can not decode related resource which is null ([#77](https://github.com/f3ath/json-api-dart/issues/77))
4355

4456
## [3.2.1] - 2020-01-01
4557
### Fixed
46-
- Incorrect URL in the example in the Client documentation ([issue](https://github.com/f3ath/json-api-dart/issues/74))
58+
- Incorrect URL in the example in the Client documentation ([#74](https://github.com/f3ath/json-api-dart/issues/74))
4759

4860
## [3.2.0] - 2019-12-30
4961
### Added
@@ -69,12 +81,13 @@ is missing. Before in such cases a `FormatException` would be thrown ([pr](https
6981

7082
## [3.0.0] - 2019-12-17
7183
### Added
72-
- Support for custom non-standard links ([issue](https://github.com/f3ath/json-api-dart/issues/61))
84+
- Support for custom non-standard links ([#61](https://github.com/f3ath/json-api-dart/issues/61))
7385
- Client supports `jsonapi` key in outgoing requests.
7486
- `Document.contentType` constant.
7587
- `IdentifierObject.fromIdentifier` factory method
7688

7789
### Changed
90+
Most of the changes are **BC-BREAKING**.
7891
- `URLBuilder` was renamed to `UrlFactory`.
7992
- `DocumentBuilder` was split into `ServerDocumentFactory` and `ClientDocumentFactory`. Some methods were renamed.
8093
- Static `decodeJson` methods were renamed to `fromJson`.
@@ -84,7 +97,7 @@ is missing. Before in such cases a `FormatException` would be thrown ([pr](https
8497
- The signature of `Controller`.
8598
- `Server` was renamed to `JsonApiServer`.
8699
- `Pagination` was renamed to `PaginationStrategy`.
87-
100+
88101
### Removed
89102
- (Server) `ResourceTarget`, `CollectionTarget`, `RelationshipTarget` classes.
90103
- `QueryParameters` interface.
@@ -93,35 +106,37 @@ is missing. Before in such cases a `FormatException` would be thrown ([pr](https
93106

94107
## [2.1.0] - 2019-12-04
95108
### Added
96-
- `onHttpCall` hook to enable raw http request/response logging ([issue](https://github.com/f3ath/json-api-dart/issues/60)).
109+
- `onHttpCall` hook to enable raw http request/response logging ([#60](https://github.com/f3ath/json-api-dart/issues/60)).
97110

98111
## [2.0.3] - 2019-09-29
99112
### Fixed
100113
- Documentation links got broken due to pub.dev update.
101114

102115
## [2.0.2] - 2019-08-01
103116
### Fixed
104-
- Meta members have incorrect type ([issue](https://github.com/f3ath/json-api-dart/issues/54)).
117+
- Meta members have incorrect type ([#54](https://github.com/f3ath/json-api-dart/issues/54)).
105118

106119
## [2.0.1] - 2019-07-12
107120
### Fixed
108121
- Readme example was outdated.
109122

110123
## [2.0.0] - 2019-07-12
124+
111125
### Changed
112126
- This package now consolidates the Client, the Server and the Document in one single library.
113-
It does not depend on `json_api_document` and `json_api_server` anymore, please remove these packages
114-
from your `pubspec.yaml`.
127+
It does not depend on `json_api_document` and `json_api_server` anymore, please remove these packages
128+
from your `pubspec.yaml`.
115129
- The min Dart SDK version bumped to `2.3.0`
116130
- The Client requires an instance of HttpClient to be passed to the constructor explicitly.
117131
- Both the Document and the Server have been refactored with lots of **BREAKING CHANGES**.
118-
See the examples and the functional tests for details.
132+
See the examples and the functional tests for details.
119133
- Meta properties are not defensively copied, but set directly. Meta property behavior is unified across
120-
the Document model.
134+
the Document model.
121135

122136
### Removed
123137
- `JsonApiParser` is removed. Use the static `decodeJson` methods in the corresponding classes instead.
124138

139+
125140
## [1.0.1] - 2019-04-05
126141
### Fixed
127142
- Bumped the dependencies versions due to a bug in `json_api_document`.
@@ -136,54 +151,55 @@ the Document model.
136151
- Renamed `client.removeToOne(...)` to `client.deleteToOne(...)`
137152

138153
## [0.5.0] - 2019-03-21
139-
### Added
140-
- Related collection pagination
141-
- Async operations support
142-
143154
### Changed
144155
- More BC-breaking changes in the Server
145156

146157
### Fixed
147-
- Location headers generated incorrectly
158+
- Location headers were incorrectly generated by Server
148159

149-
## [0.4.0] - 2019-03-17
150160
### Added
151-
- Compound documents support in Client (Server-side support is still very limited)
161+
- Related collection pagination
162+
- Async operations support
152163

164+
## [0.4.0] - 2019-03-17
153165
### Changed
154166
- Parsing logic moved out
155167
- Some other BC-breaking changes in the Document
156168
- Huge changes in the Server
157169

170+
### Added
171+
- Compound documents support in Client (Server-side support is still very limited)
172+
158173
### Fixed
159174
- Server was not setting links for resources and relationships
160175

161176
## [0.3.0] - 2019-03-16
177+
### Changed
178+
- Huge BC-breaking refactoring in the Document model which propagated everywhere
179+
162180
### Added
163181
- Resource attributes update
164182
- Resource relationships update
165183

166-
### Changed
167-
- Huge BC-breaking refactoring in the Document model which propagated everywhere
168-
169184
## [0.2.0] - 2019-03-01
170185
### Added
171186
- Improved ResourceController error handling
172187
- Resource creation
173188
- Resource deletion
174189

175-
## 0.1.0 - 2019-02-27
190+
## [0.1.0] - 2019-02-27
176191
### Added
177192
- Client: fetch resources, collections, related resources and relationships
178193

179-
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/4.3.0...HEAD
194+
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/4.3.0..HEAD
180195
[4.3.0]: https://github.com/f3ath/json-api-dart/compare/4.2.2...4.3.0
181196
[4.2.2]: https://github.com/f3ath/json-api-dart/compare/4.2.1...4.2.2
182197
[4.2.1]: https://github.com/f3ath/json-api-dart/compare/4.2.0...4.2.1
183198
[4.2.0]: https://github.com/f3ath/json-api-dart/compare/4.1.0...4.2.0
184199
[4.1.0]: https://github.com/f3ath/json-api-dart/compare/4.0.0...4.1.0
185200
[4.0.0]: https://github.com/f3ath/json-api-dart/compare/3.2.2...4.0.0
186-
[3.2.2]: https://github.com/f3ath/json-api-dart/compare/3.2.1...3.2.2
201+
[3.2.3]: https://github.com/f3ath/json-api-dart/compare/3.2.2..3.2.3
202+
[3.2.2]: https://github.com/f3ath/json-api-dart/compare/3.2.1..3.2.2
187203
[3.2.1]: https://github.com/f3ath/json-api-dart/compare/3.2.0...3.2.1
188204
[3.2.0]: https://github.com/f3ath/json-api-dart/compare/3.1.0...3.2.0
189205
[3.1.0]: https://github.com/f3ath/json-api-dart/compare/3.0.0...3.1.0
@@ -199,4 +215,5 @@ the Document model.
199215
[0.5.0]: https://github.com/f3ath/json-api-dart/compare/0.4.0...0.5.0
200216
[0.4.0]: https://github.com/f3ath/json-api-dart/compare/0.3.0...0.4.0
201217
[0.3.0]: https://github.com/f3ath/json-api-dart/compare/0.2.0...0.3.0
202-
[0.2.0]: https://github.com/f3ath/json-api-dart/compare/0.1.0...0.2.0
218+
[0.2.0]: https://github.com/f3ath/json-api-dart/compare/0.1.0...0.2.0
219+
[0.1.0]: https://github.com/f3ath/json-api-dart/releases/tag/0.1.0

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Alexey Karapetov
3+
Copyright (c) 2019-2021 Alexey Karapetov
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+2-138
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,6 @@
1-
# JSON:API for Dart/Flutter
1+
# JSON:API Client and Server for Dart/Flutter. Version 5.
22

3-
[JSON:API] is a specification for building APIs in JSON.
3+
[JSON:API] is a specification for building JSON APIs. The documentation is a work-in-progress.
44

5-
This package consists of several libraries:
6-
- The [Document library] is the core of this package. It describes the JSON:API document structure
7-
- The [Client library] is a JSON:API Client for Flutter, Web and Server-side
8-
- The [Server library] is a framework-agnostic JSON:API server implementation
9-
- The [HTTP library] is a thin abstraction of HTTP requests and responses
10-
- The [Query library] builds and parses the query parameters (page, sorting, filtering, etc)
11-
- The [Routing library] builds and matches URIs for resources, collections, and relationships
12-
13-
## Document model
14-
The main concept of JSON:API model is the [Resource].
15-
Resources are passed between the client and the server in the form of a JSON-encodable [Document].
16-
17-
## Client
18-
[JsonApiClient] is an implementation of the JSON:API client supporting all features of the JSON:API standard:
19-
- fetching resources and collections (both primary and related)
20-
- creating resources
21-
- deleting resources
22-
- updating resource attributes and relationships
23-
- direct modification of relationships (both to-one and to-many)
24-
- [async processing](https://jsonapi.org/recommendations/#asynchronous-processing)
25-
26-
The client returns back a [Response] which contains the HTTP status code, headers and the JSON:API [Document].
27-
28-
Sometimes the request URIs can be inferred from the context.
29-
For such cases you may use the [RoutingClient] which is a wrapper over the [JsonApiClient] capable of inferring the URIs.
30-
The [RoutingClient] requires an instance of [RouteFactory] to be provided.
31-
32-
[JsonApiClient] itself does not make actual HTTP calls.
33-
Instead, it calls the underlying [HttpHandler] which acts as an HTTP client (must be passed to the constructor).
34-
The library comes with an implementation of [HttpHandler] called [DartHttp] which uses the Dart's native http client.
35-
36-
## Server
37-
This is a framework-agnostic library for implementing a JSON:API server.
38-
It may be used on its own (a fully functional server implementation is included) or as a set of independent components.
39-
40-
### Request lifecycle
41-
#### HTTP request
42-
The server receives an incoming [HttpRequest] containing the HTTP headers and the body represented as a String.
43-
When this request is received, your server may decide to check for authentication or other non-JSON:API concerns
44-
to prepare for the request processing, or it may decide to fail out with an error response.
45-
46-
#### JSON:API request
47-
The [RequestConverter] is then used to convert the HTTP request to a [JsonApiRequest].
48-
[JsonApiRequest] abstracts the JSON:API specific details,
49-
such as the request target (a collection, a resource or a relationship) and the decoded body (e.g. [Resource] or [Identifier]).
50-
At this point it is possible to determine whether the request is a valid JSON:API request and to read the decoded payload.
51-
You may perform some application-specific logic, e.g. check for authentication.
52-
Each implementation of [JsonApiRequest] has the `handleWith()` method to dispatch a call to the right method of the [Controller].
53-
54-
#### Controller
55-
The [Controller] consolidates all methods to process JSON:API requests.
56-
Every controller method must return an instance of [JsonApiResponse] (or another type, the controller is generic).
57-
This library comes with a particular implementation of the [Controller] called [RepositoryController].
58-
The [RepositoryController] takes care of all JSON:API specific logic (e.g. validation, filtering, resource
59-
inclusion) and translates the JSON:API requests to calls to a resource [Repository].
60-
61-
#### Repository (optional)
62-
The [Repository] is an interface separating the data storage concerns from the specifics of the API.
63-
64-
#### JSON:API response
65-
When an instance of [JsonApiResponse] is returned from the controller, the [ResponseConverter]
66-
converts it to an [HttpResponse].
67-
The converter takes care of JSON:API transport-layer concerns.
68-
In particular, it:
69-
- generates a proper [Document], including the HATEOAS links or meta-data
70-
- encodes the document to JSON string
71-
- sets the response headers
72-
73-
#### HTTP response
74-
The generated [HttpResponse] is sent to the underlying HTTP system.
75-
This is the final step.
76-
77-
## HTTP
78-
This library is used by both the Client and the Server to abstract out the HTTP protocol specifics.
79-
The [HttpHandler] interface turns an [HttpRequest] to an [HttpResponse].
80-
The Client consumes an implementation of [HttpHandler] as a low-level HTTP client.
81-
The Server is itself an implementation of [HttpHandler].
82-
83-
## Query
84-
This is a set of classes for building avd parsing some URL query parameters defined in the standard.
85-
- [Fields] for [Sparse fieldsets]
86-
- [Include] for [Inclusion of Related Resources]
87-
- [Page] for [Collection Pagination]
88-
- [Sort] for [Collection Sorting]
89-
90-
## Routing
91-
Defines the logic for constructing and matching URLs for resources, collections and relationships.
92-
The URL construction is used by both the Client (See [RoutingClient] for instance) and the Server libraries.
93-
The [StandardRouting] implements the [Recommended URL design].
945

956
[JSON:API]: https://jsonapi.org
96-
[Sparse fieldsets]: https://jsonapi.org/format/#fetching-sparse-fieldsets
97-
[Inclusion of Related Resources]: https://jsonapi.org/format/#fetching-includes
98-
[Collection Pagination]: https://jsonapi.org/format/#fetching-pagination
99-
[Collection Sorting]: https://jsonapi.org/format/#fetching-sorting
100-
[Recommended URL design]: https://jsonapi.org/recommendations/#urls
101-
102-
[Client library]: https://pub.dev/documentation/json_api/latest/client/client-library.html
103-
[Server library]: https://pub.dev/documentation/json_api/latest/server/server-library.html
104-
[Document library]: https://pub.dev/documentation/json_api/latest/document/document-library.html
105-
[Query library]: https://pub.dev/documentation/json_api/latest/query/query-library.html
106-
[Routing library]: https://pub.dev/documentation/json_api/latest/uri_design/uri_design-library.html
107-
[HTTP library]: https://pub.dev/documentation/json_api/latest/http/http-library.html
108-
109-
110-
[Resource]: https://pub.dev/documentation/json_api/latest/document/Resource-class.html
111-
[Identifier]: https://pub.dev/documentation/json_api/latest/document/Identifier-class.html
112-
[Document]: https://pub.dev/documentation/json_api/latest/document/Document-class.html
113-
[JsonApiClient]: https://pub.dev/documentation/json_api/latest/client/JsonApiClient-class.html
114-
115-
116-
[Response]: https://pub.dev/documentation/json_api/latest/client/Response-class.html
117-
[RoutingClient]: https://pub.dev/documentation/json_api/latest/client/RoutingClient-class.html
118-
[DartHttp]: https://pub.dev/documentation/json_api/latest/client/DartHttp-class.html
119-
120-
121-
[RequestConverter]: https://pub.dev/documentation/json_api/latest/server/RequestConverter-class.html
122-
[JsonApiResponse]: https://pub.dev/documentation/json_api/latest/server/JsonApiResponse-class.html
123-
[ResponseConverter]: https://pub.dev/documentation/json_api/latest/server/ResponseConverter-class.html
124-
[JsonApiRequest]: https://pub.dev/documentation/json_api/latest/server/JsonApiRequest-class.html
125-
[Controller]: https://pub.dev/documentation/json_api/latest/server/Controller-class.html
126-
[Repository]: https://pub.dev/documentation/json_api/latest/server/Repository-class.html
127-
[RepositoryController]: https://pub.dev/documentation/json_api/latest/server/RepositoryController-class.html
128-
129-
130-
[HttpHandler]: https://pub.dev/documentation/json_api/latest/http/HttpHandler-class.html
131-
[HttpRequest]: https://pub.dev/documentation/json_api/latest/http/HttpRequest-class.html
132-
[HttpResponse]: https://pub.dev/documentation/json_api/latest/http/HttpResponse-class.html
133-
134-
135-
[Fields]: https://pub.dev/documentation/json_api/latest/query/Fields-class.html
136-
[Include]: https://pub.dev/documentation/json_api/latest/query/Include-class.html
137-
[Page]: https://pub.dev/documentation/json_api/latest/query/Page-class.html
138-
[Sort]: https://pub.dev/documentation/json_api/latest/query/Sort-class.html
139-
140-
141-
[RouteFactory]: https://pub.dev/documentation/json_api/latest/routing/RouteFactory-class.html
142-
[StandardRouting]: https://pub.dev/documentation/json_api/latest/routing/StandardRouting-class.html

0 commit comments

Comments
 (0)