-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
88 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import 'package:json_path/src/filter_not_found.dart'; | ||
import 'package:json_path/src/json_path_match.dart'; | ||
|
||
class MatchingContext { | ||
const MatchingContext(this.filters); | ||
const MatchingContext(this._filters); | ||
|
||
/// Named callback filters | ||
final Map<String, CallbackFilter> filters; | ||
final Map<String, CallbackFilter> _filters; | ||
|
||
CallbackFilter getFilter(String name) { | ||
final filter = _filters[name]; | ||
if (filter == null) { | ||
throw FilterNotFound('Callback filter "$name" not found'); | ||
} | ||
return filter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
import 'package:json_path/src/filter_not_found.dart'; | ||
import 'package:json_path/src/json_path_match.dart'; | ||
import 'package:json_path/src/selector.dart'; | ||
import 'package:json_path/src/selector/wildcard.dart'; | ||
|
||
class CallbackFilter implements Selector { | ||
CallbackFilter(this.name); | ||
class CallbackFilter extends Wildcard { | ||
const CallbackFilter(this.name); | ||
|
||
final String name; | ||
|
||
@override | ||
Iterable<JsonPathMatch> apply(JsonPathMatch match) sync* { | ||
final filter = match.context.filters[name]; | ||
if (filter == null) { | ||
throw FilterNotFound('Callback filter "$name" not found'); | ||
} | ||
yield* const Wildcard().apply(match).where(filter); | ||
} | ||
Iterable<JsonPathMatch> apply(JsonPathMatch match) => | ||
super.apply(match).where(match.context.getFilter(name)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
import 'package:json_path/src/json_path_match.dart'; | ||
import 'package:json_path/src/selector.dart'; | ||
import 'package:json_path/src/selector/wildcard.dart'; | ||
|
||
class ExpressionFilter implements Selector { | ||
class ExpressionFilter extends Wildcard { | ||
ExpressionFilter(this.eval); | ||
|
||
final Eval eval; | ||
|
||
@override | ||
Iterable<JsonPathMatch> apply(JsonPathMatch match) sync* { | ||
yield* const Wildcard().apply(match).where((match) { | ||
final val = eval(match); | ||
return (val == true || | ||
(val is num && val != 0) || | ||
(val is String && val.isNotEmpty)); | ||
}); | ||
} | ||
Iterable<JsonPathMatch> apply(JsonPathMatch match) => | ||
super.apply(match).where((match) { | ||
final val = eval(match); | ||
return (val == true || | ||
(val is num && val != 0) || | ||
(val is String && val.isNotEmpty)); | ||
}); | ||
} | ||
|
||
typedef Eval<T> = T Function(JsonPathMatch match); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import 'package:json_path/src/json_path_match.dart'; | ||
import 'package:json_path/src/selector.dart'; | ||
|
||
typedef Filter = Iterable<JsonPathMatch> Function( | ||
Iterable<JsonPathMatch> matches); | ||
|
||
class Sequence implements Selector { | ||
Sequence(Iterable<Selector> selectors) | ||
: _filter = selectors.fold<Filter>( | ||
: _filter = selectors.fold<_Filter>( | ||
(_) => _, | ||
(filter, selector) => (matches) => | ||
filter(matches).map(selector.apply).expand((_) => _)); | ||
|
||
final Filter _filter; | ||
final _Filter _filter; | ||
|
||
@override | ||
Iterable<JsonPathMatch> apply(JsonPathMatch match) => _filter([match]); | ||
} | ||
|
||
typedef _Filter = Iterable<JsonPathMatch> Function( | ||
Iterable<JsonPathMatch> matches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
name: json_path | ||
version: 0.3.0-nullsafety.3 | ||
description: Implementation of JSONPath expressions like "$.store.book[2].price". Can read and set values in parsed JSON objects. | ||
version: 0.3.0 | ||
description: Implementation of JSONPath expressions like "$.store.book[2].price". Reads and writes values in parsed JSON objects. | ||
homepage: "https://github.com/f3ath/jessie" | ||
|
||
environment: | ||
sdk: '>=2.12.0-29 <3.0.0' | ||
|
||
dependencies: | ||
rfc_6901: ^0.0.0-nullsafety.7 | ||
petitparser: ^4.0.0-nullsafety | ||
rfc_6901: ^0.1.0 | ||
petitparser: ^4.0.0 | ||
|
||
dev_dependencies: | ||
pedantic: ^1.10.0-nullsafety | ||
test: ^1.16.0-nullsafety | ||
pedantic: ^1.10.0 | ||
test: ^1.16.2 | ||
test_coverage: ^0.5.0 | ||
path: ^1.8.0-nullsafety | ||
yaml: ^3.0.0-nullsafety | ||
path: ^1.8.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters