|
1 |
| -import 'package:http_interop/http_interop.dart'; |
| 1 | +import 'package:http_interop/http_interop.dart' as i; |
2 | 2 | import 'package:json_api/document.dart';
|
| 3 | +import 'package:json_api/src/client/response.dart'; |
3 | 4 |
|
4 | 5 | /// A response to a relationship fetch request.
|
5 | 6 | class RelationshipFetched<R extends Relationship> {
|
6 |
| - RelationshipFetched(this.httpResponse, this.relationship); |
| 7 | + RelationshipFetched(this.rawResponse, this.relationship); |
7 | 8 |
|
8 |
| - static RelationshipFetched<ToMany> many(Response httpResponse, Map json) => |
9 |
| - RelationshipFetched(httpResponse, InboundDocument(json).asToMany()) |
10 |
| - ..included.addAll(InboundDocument(json).included()); |
| 9 | + static RelationshipFetched<ToMany> many(Response response) { |
| 10 | + final document = InboundDocument(response.document ?? |
| 11 | + (throw FormatException('The document must not be empty'))); |
| 12 | + return RelationshipFetched(response, document.asToMany()) |
| 13 | + ..included.addAll(document.included()); |
| 14 | + } |
11 | 15 |
|
12 |
| - static RelationshipFetched<ToOne> one(Response httpResponse, Map json) => |
13 |
| - RelationshipFetched(httpResponse, InboundDocument(json).asToOne()) |
14 |
| - ..included.addAll(InboundDocument(json).included()); |
| 16 | + static RelationshipFetched<ToOne> one(Response response) { |
| 17 | + final document = InboundDocument(response.document ?? |
| 18 | + (throw FormatException('The document must not be empty'))); |
| 19 | + return RelationshipFetched(response, document.asToOne()) |
| 20 | + ..included.addAll(document.included()); |
| 21 | + } |
| 22 | + |
| 23 | + // coverage:ignore-start |
| 24 | + /// The raw HTTP response |
| 25 | + @Deprecated('Use rawResponse.httpResponse instead') |
| 26 | + i.Response get httpResponse => rawResponse.httpResponse; |
| 27 | + // coverage:ignore-end |
| 28 | + |
| 29 | + /// The raw JSON:API response |
| 30 | + final Response rawResponse; |
15 | 31 |
|
16 |
| - final Response httpResponse; |
17 | 32 | final R relationship;
|
18 | 33 | final included = <Resource>[];
|
19 | 34 | }
|
0 commit comments