Intro
All deepjs queries tools produce and work hand in hand with particular properties descriptors that contain all informations on queried/matched properties, that allow to manipulate associated json-schemas, paths or ancestors of those properties.
Descriptor content
{
// a bool that define it's identity. (it replace instanceOf)
_deep_query_node_:true,
// the root descriptor (if the current node it's the root itself : this properties is undefined)
root:{ _deep_query_node_ },
// the ancestor descriptor (if the current node it's the root itself : this properties is undefined)
ancestor:{ _deep_query_node_ },
// a string that gives the property path (slash delimitted) from root.
path:String,
// an array providing splitted path on '/' (so String)
paths:[Strings],
// a string that give last part of path (the key of the property)
key: String,
// a schema (so an Object) if any.
schema:Object,
// the value of the property
value: *
}
Node tools
All deepjs node's tools are placed in deep.utils.nodes namespace.
deep.utils.nodes.val(result)
Get value(s) from queries results (descriptors set or real values).
On an array of descriptors : return array of values
var r = deep.query({ a:true, b:"hello" }, "./*", { fullOutput:true });
deep.log(deep.utils.nodes.val(r));
On a single descriptor : return single value.
var r = deep.query({ a:true, b:"hello" }, "./b", { fullOutput:true });
deep.log(deep.utils.nodes.val(r));
Anything else : return the value.
deep.log(deep.utils.nodes.val("hello world"));
deep.log(deep.utils.nodes.val([1,2]));
deep.utils.nodes.paths(nodes)
Get path(s) from node(s).
Always return an array.
var r = deep.query({ a:true, b:"hello" }, "./*", { fullOutput:true });
deep.log(deep.utils.nodes.paths(r));
deep.utils.nodes.schemas(nodes)
Get schema(s) from node(s).
Always return an array.
var r = deep.query({ a:true, b:"hello" }, "./*", {
fullOutput:true,
schema:{
properties:{
a:{ type:"boolean", required:true },
b:{ type:"string", required:true }
}
}
});
deep.log(deep.utils.nodes.schemas(r));
deep.utils.nodes.map(nodes)
Transform node(s) value. So replace original value by the one returned by provided callback.
Could work on a single descriptor or on a array of descriptors.
Return either a promise (that will return transformed value(s)) or directly the transformed value(s) if there is nothing to wait.
Straight query (so single node) :
var r = deep.query({ a:true, b:"hello" }, "./a", { fullOutput:true });
deep.utils.nodes.map(r, function(node){
return node.value+":transformed";
});
deep.log(deep.utils.nodes.val(r));
Full query (so array of nodes) :
var r = deep.query({ a:true, b:"hello" }, "./*", { fullOutput:true });
deep.utils.nodes.map(r, function(node){
return node.value+":transformed";
});
deep.log(deep.utils.nodes.val(r));
deep.utils.nodes.deepLoad(nodes, context, destructive)
Perform a deepLoad on node(s).
You should normally not use this directly.
See deepLoad for more infos.
var r = deep.query({ a:"eval::1+3", b:{ c:"dummy::world" } }, "./*", { fullOutput:true });
deep.utils.nodes.deepLoad(r).log();
deep.utils.nodes.print(result)
Print node(s).
var r = deep.query({ a:true, b:"hello" }, "./*", { fullOutput:true });
deep.log(deep.utils.nodes.print(r));
deep.utils.nodes.root(obj, schema, opt)
Create a root node from an object and returns it. Schema is optional.
(mainly used internaly by deepjs)
var rootNode = deep.utils.nodes.root({ a:true, b:12 });
deep.log(rootNode);
deep.utils.nodes.create(parentNode, key)
Create a child node from a node. If parent node contains a schema, it catchs the child's schema and stores it in returned node.
(mainly used internaly by deepjs)
deep.utils.nodes.clone(node)
Clone a descriptor node and returns it.
(mainly used internaly by deepjs)