Skip to content

Commit

Permalink
Update query.js
Browse files Browse the repository at this point in the history
Implemented a rudimentary logging system, specifically an array (queue) for the following: jsonQuery._log.func & jsonQuery._log.query. In the future need to add amt to keep or implement a tokenized session retrieval for the logs and/or add a parameter to enable console logging per jsonQuery.query() call. In the mean time the logs can be cleared on demand with jsonQuery._log.resetLogs().

Implemented full support for ES6 lambdas as well as normal functions. I.E. Array.map(e => e.prop) or Array.map(function(e) { return e.prop }). Everything between the parenthesis will not be further interpreted, so valid JS code is expected. This was implemented specifically for the usage in combination with prototyped functions from LINQJS (I.E. https://jsfiddle.net/x7g0zf19/1/): obj["$..prop.Sum()"].

Cleaned up arguments usage. Previously a hard limit of 9 args could be passed and used in the format '$#' where # was a digit between 1 and 9. Now you can pass any amount of arguments (for whatever reason). The function definition is generated dynamically based on the # of arguments passed to the query function.

Added support for automatically setting Object.prototype.query() to be bound to automatically calling jsonQuery.query() via jsonQuery.setObjProto() (only needs called once per JS instance), so that the query method can easily be called on any object with little code: obj.query("$..prop"). This is taken to the next level with jsonQuery.proxyIndexer() (ES6 only) which implements a proxy over an object. All the proxy does is monitor/track the usage of any property GET checking to see IF the requested property is not present AND the character '$' is present at the beginning of the property string, then it will perform that jsonQuery.query() for you using the specified property name: obj["$..query"]. This is the simplest way to implement and effectively use the jsonQuery library, since the whole point is to use as little syntax as possible to get the desired result, yet still have the ability to do complex operations, which can still be pretty simple.

Lots of code cleanup, spacing and a few rewrites for ES6 syntax. Ideally the whole thing will be converted to ES6 sugar-syntax since it is much more readable and typically cleaner. A transpiler can be used to convert for ES5 or older compatibility (proxyIndexer() only supported on ES6).

Todo:

* Remove $obj reference and use only $.
* Further code cleanup and transpilation to ES6
* Investigate possibility of parental references
* Attempt to implement escape characters for keywords and/or to prevent entire sequences of code from being processed by the regex rules (similar to how strings and lambdas/funcs are currently handled)
* Implement a regex.replace engine/system that can be put into a modularized sequence for clearer visibility & code readability.
  • Loading branch information
gerneio committed Jan 7, 2019
1 parent 9244b64 commit 28dce7e
Showing 1 changed file with 376 additions and 330 deletions.
Loading

0 comments on commit 28dce7e

Please sign in to comment.