publish 0.2.3 - fixed #7

This commit is contained in:
freestrings 2019-06-24 14:36:49 +09:00
commit f1fda2af13
7 changed files with 58 additions and 51 deletions

View File

@ -1,9 +1,9 @@
[package]
name = "jsonpath_lib"
version = "0.2.2"
version = "0.2.3"
authors = ["Changseok Han <freestrings@gmail.com>"]
description = "It is JsonPath engine written in Rust. it provide a similar API interface in Webassembly and Javascript also. - Webassembly Demo: https://freestrings.github.io/jsonpath"
description = "It is JsonPath engine written in Rust. it provide a similar API interface in Webassembly and Javascript too. - Webassembly Demo: https://freestrings.github.io/jsonpath"
readme = "README.md"
keywords = ["jsonpath", "json", "webassembly", "nodejs", "javascript"]
@ -19,11 +19,10 @@ travis-ci = { repository = "freestrings/jsonpath", branch = "master" }
[dependencies]
log = "0.4"
env_logger = "0.6.0"
env_logger = "0.6"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
indexmap = "1.0.2"
array_tool = "~1.0.3"
array_tool = "1.0.3"
[dev-dependencies]
bencher = "0.1.5"

View File

@ -8,7 +8,7 @@
`Rust` 버전 [JsonPath](https://goessner.net/articles/JsonPath/) 구현이다. `Webassembly``Javascript`에서도 유사한 API 인터페이스를 제공 한다.
It is JsonPath [JsonPath](https://goessner.net/articles/JsonPath/) engine written in `Rust`. it provide a similar API interface in `Webassembly` and` Javascript` also.
It is JsonPath [JsonPath](https://goessner.net/articles/JsonPath/) engine written in `Rust`. it provide a similar API interface in `Webassembly` and` Javascript` too.
- [Webassembly Demo](https://freestrings.github.io/jsonpath/)
- [NPM jsonpath-wasm - webassembly](https://www.npmjs.com/package/jsonpath-wasm)

View File

@ -14,7 +14,7 @@ exclude = ["artifacts.json", "index.node"]
neon-build = "0.2.0"
[dependencies]
jsonpath_lib = "0.2.2"
jsonpath_lib = "0.2.3"
#jsonpath_lib = { path = "../../" }
neon = "0.2.0"
serde_json = { version = "1.0", features = ["preserve_order"] }

View File

@ -894,35 +894,35 @@ describe('ISSUE test', () => {
}
});
// it('Invalid wildcard filter results #7', (done) => {
//
// function select(json, expected, paths) {
// for (var i = 0 ; i < paths.length ; i++) {
// let result = jsonpath.select(json, paths[i]);
// if (JSON.stringify(result) !== JSON.stringify(expected)) {
// throw Error("Error: " + paths[i]);
// }
// }
// }
//
// select(
// ["string", 42, { "key": "value" }, [0, 1]],
// ["string", 42, { "key": "value" }, [0, 1]],
// ["$.*", "$[*]"]
// );
//
// select(
// ["string", 42, { "key": "value" }, [0, 1]],
// [ "string", 42, { "key" : "value" }, [ 0, 1 ], "value", 0, 1 ],
// ["$..*", "$..[*]"]
// );
//
// select(
// ["string", 42, { "key": "value" }, [0, 1]],
// ["value", 0, 1],
// ["$.*.*", "$[*].*", "$.*[*]", "$[*][*]"]
// );
//
// done();
// });
it('Invalid wildcard filter results #7', (done) => {
function select(json, expected, paths) {
for (var i = 0 ; i < paths.length ; i++) {
let result = jsonpath.select(json, paths[i]);
if (JSON.stringify(result) !== JSON.stringify(expected)) {
throw Error("Error: " + paths[i]);
}
}
}
select(
["string", 42, { "key": "value" }, [0, 1]],
["string", 42, { "key": "value" }, [0, 1]],
["$.*", "$[*]"]
);
select(
["string", 42, { "key": "value" }, [0, 1]],
[ "string", 42, { "key" : "value" }, [ 0, 1 ], "value", 0, 1 ],
["$..*", "$..[*]"]
);
select(
["string", 42, { "key": "value" }, [0, 1]],
["value", 0, 1],
["$.*.*", "$[*].*", "$.*[*]", "$[*][*]"]
);
done();
});
});

View File

@ -125,7 +125,6 @@
extern crate array_tool;
extern crate core;
extern crate env_logger;
extern crate indexmap;
#[macro_use]
extern crate log;
extern crate serde;

View File

@ -2,7 +2,6 @@ use std::collections::HashSet;
use std::fmt;
use array_tool::vec::{Intersect, Union};
use indexmap::IndexMap;
use serde_json::{Number, Value};
use parser::parser::*;
@ -1167,7 +1166,8 @@ impl SelectorMut {
origin: &Value,
target: &mut Vec<&Value>,
tokens: &mut Vec<String>,
visited: &mut IndexMap<*const Value, Vec<String>>,
visited: &mut HashSet<*const Value>,
visited_order: &mut Vec<Vec<String>>,
) -> bool {
trace!("{:?}, {:?}", target, tokens);
@ -1177,7 +1177,9 @@ impl SelectorMut {
target.retain(|t| {
if std::ptr::eq(origin, *t) {
visited.insert(*t, tokens.to_vec());
if visited.insert(*t) {
visited_order.push(tokens.to_vec());
}
false
} else {
true
@ -1188,7 +1190,7 @@ impl SelectorMut {
Value::Array(vec) => {
for (i, v) in vec.iter().enumerate() {
tokens.push(i.to_string());
if _walk(v, target, tokens, visited) {
if _walk(v, target, tokens, visited, visited_order) {
return true;
}
tokens.pop();
@ -1197,7 +1199,7 @@ impl SelectorMut {
Value::Object(map) => {
for (k, v) in map {
tokens.push(k.clone());
if _walk(v, target, tokens, visited) {
if _walk(v, target, tokens, visited, visited_order) {
return true;
}
tokens.pop();
@ -1209,14 +1211,21 @@ impl SelectorMut {
return false;
}
let mut visited = IndexMap::new();
let mut visited = HashSet::new();
let mut visited_order = Vec::new();
if let Some(origin) = &self.value {
let mut tokens = Vec::new();
_walk(origin, &mut result, &mut tokens, &mut visited);
_walk(
origin,
&mut result,
&mut tokens,
&mut visited,
&mut visited_order,
);
}
visited.iter().map(|(_, v)| v.to_vec()).collect()
visited_order
}
pub fn delete(&mut self) -> Result<&mut Self, JsonPathError> {

View File

@ -1,6 +1,6 @@
[package]
name = "jsonpath-wasm"
version = "0.2.2"
version = "0.2.3"
authors = ["Changseok Han <freestrings@gmail.com>"]
description = "It is Webassembly version of jsonpath_lib that is JsonPath engine written in Rust - Demo: https://freestrings.github.io/jsonpath"
keywords = ["jsonpath", "json", "webassembly", "parsing", "rust"]
@ -14,10 +14,10 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook", "wee_alloc"]
[dependencies]
cfg-if = "0.1.2"
cfg-if = "0.1"
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
console_error_panic_hook = { version = "0.1.1", optional = true }
wee_alloc = { version = "0.4.2", optional = true }
console_error_panic_hook = { version = "0.1", optional = true }
wee_alloc = { version = "0.4", optional = true }
jsonpath_lib = { path = "../" }
serde = "1.0"