Skip to content

Commit 044e410

Browse files
committed
v7
1 parent 022c2e2 commit 044e410

File tree

7 files changed

+51
-61
lines changed

7 files changed

+51
-61
lines changed

.github/workflows/publish.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Publish to pub.dev
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+*'
7+
8+
jobs:
9+
publish:
10+
permissions:
11+
id-token: write # Required for authentication using OIDC
12+
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
13+
# with:
14+
# working-directory: path/to/package/within/repository

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ All notable changes to this project will be documented in this file.
44
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

7-
## [Unreleased]
7+
## [7.0.0] - 2023-11-12
88
### Changed
9-
- Migrated to http\_interop v1.
9+
- Migrated to `http_interop` v1.
1010

1111
## [6.0.1] - 2023-09-11
1212
### Fixed
@@ -246,7 +246,7 @@ the Document model.
246246
### Added
247247
- Client: fetch resources, collections, related resources and relationships
248248

249-
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/6.0.1...HEAD
249+
[7.0.0]: https://github.com/f3ath/json-api-dart/compare/6.0.1...7.0.0
250250
[6.0.1]: https://github.com/f3ath/json-api-dart/compare/6.0.0...6.0.1
251251
[6.0.0]: https://github.com/f3ath/json-api-dart/compare/5.4.0...6.0.0
252252
[5.4.0]: https://github.com/f3ath/json-api-dart/compare/5.3.0...5.4.0

lib/src/document/inbound_document.dart

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,11 @@ class _Parser {
147147

148148
/// Decodes Link from [json]. Returns the decoded object.
149149
/// If the [json] has incorrect format, throws [FormatException].
150-
Link _link(Object json) {
151-
if (json is String) return Link(Uri.parse(json));
152-
if (json is Map) {
153-
return Link(Uri.parse(json['href']))..meta.addAll(meta(json));
154-
}
155-
throw FormatException('Invalid JSON');
156-
}
150+
Link _link(Object json) => switch (json) {
151+
String() => Link(Uri.parse(json)),
152+
Map() => Link(Uri.parse(json['href']))..meta.addAll(meta(json)),
153+
_ => throw FormatException('Invalid JSON')
154+
};
157155

158156
Map<String, Object?> _getAttributes(Map json) =>
159157
json.get<Map<String, Object?>>('attributes', orGet: () => {});
@@ -166,25 +164,19 @@ class _Parser {
166164
.get<Map>('relationships', orGet: () => {})
167165
.map((key, value) => MapEntry(key, newRelationship(value)));
168166

169-
Relationship _rel(data) {
170-
if (data == null) return ToOne.empty();
171-
if (data is Map) return ToOne(identifier(data));
172-
if (data is List) return ToMany(data.whereType<Map>().map(identifier));
173-
throw FormatException('Invalid relationship object');
174-
}
175-
176-
NewRelationship _newRel(data) {
177-
if (data == null) {
178-
return NewToOne.empty();
179-
}
180-
if (data is Map) {
181-
return NewToOne(newIdentifier(data));
182-
}
183-
if (data is List) {
184-
return NewToMany(data.whereType<Map>().map(newIdentifier));
185-
}
186-
throw FormatException('Invalid relationship object');
187-
}
167+
Relationship _rel(data) => switch (data) {
168+
null => ToOne.empty(),
169+
Map() => ToOne(identifier(data)),
170+
List() => ToMany(data.whereType<Map>().map(identifier)),
171+
_ => throw FormatException('Invalid relationship object')
172+
};
173+
174+
NewRelationship _newRel(data) => switch (data) {
175+
null => NewToOne.empty(),
176+
Map() => NewToOne(newIdentifier(data)),
177+
List() => NewToMany(data.whereType<Map>().map(newIdentifier)),
178+
_ => throw FormatException('Invalid relationship object')
179+
};
188180
}
189181

190182
extension _TypedGeter on Map {

lib/src/document/new_relationship.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class NewRelationship with IterableMixin<NewIdentifier> {
1212
if (meta.isNotEmpty) 'meta': meta,
1313
};
1414

15-
// coverage:ignore-start
1615
@override
1716
Iterator<NewIdentifier> get iterator => <NewIdentifier>[].iterator;
18-
// coverage:ignore-end
1917
}

lib/src/document/new_resource.dart

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,12 @@ class NewResource {
6969
return _toIdentifier(identifier, id);
7070
}
7171

72-
Identifier _toIdentifier(NewIdentifier identifier, String id) {
73-
switch (identifier) {
74-
case Identifier():
75-
return identifier;
76-
case LocalIdentifier():
77-
if (identifier.type == type && identifier.lid == lid) {
78-
return identifier.toIdentifier(id);
79-
}
80-
throw StateError(
81-
'Unmatched local id: "${identifier.lid}". Expected "$lid".');
82-
}
83-
}
72+
Identifier _toIdentifier(NewIdentifier identifier, String id) =>
73+
switch (identifier) {
74+
Identifier() => identifier,
75+
LocalIdentifier() => (identifier.type == type && identifier.lid == lid)
76+
? identifier.toIdentifier(id)
77+
: throw StateError(
78+
'Unmatched local id: "${identifier.lid}". Expected "$lid".')
79+
};
8480
}

lib/src/routing/standard_uri_design.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,14 @@ class StandardUriDesign implements UriDesign {
1111
/// `/books`, `/books/42`, `/books/42/authors`
1212
static final pathOnly = StandardUriDesign(Uri(path: '/'));
1313

14-
static Target? matchTarget(Uri uri) {
15-
final s = uri.pathSegments;
16-
if (s.length == 1) {
17-
return Target(s.first);
18-
}
19-
if (s.length == 2) {
20-
return ResourceTarget(s.first, s.last);
21-
}
22-
if (s.length == 3) {
23-
return RelatedTarget(s.first, s[1], s.last);
24-
}
25-
if (s.length == 4 && s[2] == 'relationships') {
26-
return RelationshipTarget(s.first, s[1], s.last);
27-
}
28-
return null;
29-
}
14+
static Target? matchTarget(Uri uri) => switch ((uri.pathSegments)) {
15+
[var type] => Target(type),
16+
[var type, var id] => ResourceTarget(type, id),
17+
[var type, var id, var rel] => RelatedTarget(type, id, rel),
18+
[var type, var id, 'relationships', var rel] =>
19+
RelationshipTarget(type, id, rel),
20+
_ => null
21+
};
3022

3123
final Uri base;
3224

pubspec.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ environment:
66
sdk: '>=3.1.0 <4.0.0'
77

88
dependencies:
9-
http_parser: ^4.0.0
109
http_interop: ^1.0.0
1110

1211
dev_dependencies:
@@ -20,7 +19,6 @@ dev_dependencies:
2019
http_interop_http: ^0.7.0
2120
http_interop_io: ^0.7.0
2221

23-
2422
cider:
2523
link_template:
2624
diff: https://github.com/f3ath/json-api-dart/compare/%from%...%to%

0 commit comments

Comments
 (0)