Skip to content

Commit

Permalink
v7
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath committed Nov 13, 2023
1 parent 022c2e2 commit 044e410
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 61 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Publish to pub.dev

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'

jobs:
publish:
permissions:
id-token: write # Required for authentication using OIDC
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
# with:
# working-directory: path/to/package/within/repository
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ 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).

## [Unreleased]
## [7.0.0] - 2023-11-12
### Changed
- Migrated to http\_interop v1.
- Migrated to `http_interop` v1.

## [6.0.1] - 2023-09-11
### Fixed
Expand Down Expand Up @@ -246,7 +246,7 @@ the Document model.
### Added
- Client: fetch resources, collections, related resources and relationships

[Unreleased]: https://github.com/f3ath/json-api-dart/compare/6.0.1...HEAD
[7.0.0]: https://github.com/f3ath/json-api-dart/compare/6.0.1...7.0.0
[6.0.1]: https://github.com/f3ath/json-api-dart/compare/6.0.0...6.0.1
[6.0.0]: https://github.com/f3ath/json-api-dart/compare/5.4.0...6.0.0
[5.4.0]: https://github.com/f3ath/json-api-dart/compare/5.3.0...5.4.0
Expand Down
44 changes: 18 additions & 26 deletions lib/src/document/inbound_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,11 @@ class _Parser {

/// Decodes Link from [json]. Returns the decoded object.
/// If the [json] has incorrect format, throws [FormatException].
Link _link(Object json) {
if (json is String) return Link(Uri.parse(json));
if (json is Map) {
return Link(Uri.parse(json['href']))..meta.addAll(meta(json));
}
throw FormatException('Invalid JSON');
}
Link _link(Object json) => switch (json) {
String() => Link(Uri.parse(json)),
Map() => Link(Uri.parse(json['href']))..meta.addAll(meta(json)),
_ => throw FormatException('Invalid JSON')
};

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

Relationship _rel(data) {
if (data == null) return ToOne.empty();
if (data is Map) return ToOne(identifier(data));
if (data is List) return ToMany(data.whereType<Map>().map(identifier));
throw FormatException('Invalid relationship object');
}

NewRelationship _newRel(data) {
if (data == null) {
return NewToOne.empty();
}
if (data is Map) {
return NewToOne(newIdentifier(data));
}
if (data is List) {
return NewToMany(data.whereType<Map>().map(newIdentifier));
}
throw FormatException('Invalid relationship object');
}
Relationship _rel(data) => switch (data) {
null => ToOne.empty(),
Map() => ToOne(identifier(data)),
List() => ToMany(data.whereType<Map>().map(identifier)),
_ => throw FormatException('Invalid relationship object')
};

NewRelationship _newRel(data) => switch (data) {
null => NewToOne.empty(),
Map() => NewToOne(newIdentifier(data)),
List() => NewToMany(data.whereType<Map>().map(newIdentifier)),
_ => throw FormatException('Invalid relationship object')
};
}

extension _TypedGeter on Map {
Expand Down
2 changes: 0 additions & 2 deletions lib/src/document/new_relationship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class NewRelationship with IterableMixin<NewIdentifier> {
if (meta.isNotEmpty) 'meta': meta,
};

// coverage:ignore-start
@override
Iterator<NewIdentifier> get iterator => <NewIdentifier>[].iterator;
// coverage:ignore-end
}
20 changes: 8 additions & 12 deletions lib/src/document/new_resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,12 @@ class NewResource {
return _toIdentifier(identifier, id);
}

Identifier _toIdentifier(NewIdentifier identifier, String id) {
switch (identifier) {
case Identifier():
return identifier;
case LocalIdentifier():
if (identifier.type == type && identifier.lid == lid) {
return identifier.toIdentifier(id);
}
throw StateError(
'Unmatched local id: "${identifier.lid}". Expected "$lid".');
}
}
Identifier _toIdentifier(NewIdentifier identifier, String id) =>
switch (identifier) {
Identifier() => identifier,
LocalIdentifier() => (identifier.type == type && identifier.lid == lid)
? identifier.toIdentifier(id)
: throw StateError(
'Unmatched local id: "${identifier.lid}". Expected "$lid".')
};
}
24 changes: 8 additions & 16 deletions lib/src/routing/standard_uri_design.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@ class StandardUriDesign implements UriDesign {
/// `/books`, `/books/42`, `/books/42/authors`
static final pathOnly = StandardUriDesign(Uri(path: '/'));

static Target? matchTarget(Uri uri) {
final s = uri.pathSegments;
if (s.length == 1) {
return Target(s.first);
}
if (s.length == 2) {
return ResourceTarget(s.first, s.last);
}
if (s.length == 3) {
return RelatedTarget(s.first, s[1], s.last);
}
if (s.length == 4 && s[2] == 'relationships') {
return RelationshipTarget(s.first, s[1], s.last);
}
return null;
}
static Target? matchTarget(Uri uri) => switch ((uri.pathSegments)) {
[var type] => Target(type),
[var type, var id] => ResourceTarget(type, id),
[var type, var id, var rel] => RelatedTarget(type, id, rel),
[var type, var id, 'relationships', var rel] =>
RelationshipTarget(type, id, rel),
_ => null
};

final Uri base;

Expand Down
2 changes: 0 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ environment:
sdk: '>=3.1.0 <4.0.0'

dependencies:
http_parser: ^4.0.0
http_interop: ^1.0.0

dev_dependencies:
Expand All @@ -20,7 +19,6 @@ dev_dependencies:
http_interop_http: ^0.7.0
http_interop_io: ^0.7.0


cider:
link_template:
diff: https://github.com/f3ath/json-api-dart/compare/%from%...%to%
Expand Down

0 comments on commit 044e410

Please sign in to comment.