|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var Q = require('q'); |
| 4 | + |
| 5 | +function qryqGraph(context) { |
| 6 | + var api = context.api; |
| 7 | + if (typeof api !== 'object') { |
| 8 | + throw new Error('Expected an API object'); |
| 9 | + } |
| 10 | + |
| 11 | + var fluent = { |
| 12 | + queries: [], |
| 13 | + query: query, |
| 14 | + api: api, |
| 15 | + input: input, |
| 16 | + depends: depends, |
| 17 | + filterOutput: filterOutput, |
| 18 | + allQueries: allQueries, |
| 19 | + run: run, |
| 20 | + }; |
| 21 | + var currentQuery; |
| 22 | + |
| 23 | + /** |
| 24 | + * query begins describing a new query. |
| 25 | + * subsequent calls to input, depends, and filterOutput will apply to this query |
| 26 | + * |
| 27 | + * @param id {string} |
| 28 | + * @return {Fluent} |
| 29 | + */ |
| 30 | + function query(id) { |
| 31 | + //TODO |
| 32 | + return fluent; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * api specifies the name of the API the current query should invoke |
| 37 | + * |
| 38 | + * @param name {string} |
| 39 | + * @return {Fluent} |
| 40 | + */ |
| 41 | + function api(name) { |
| 42 | + //TODO |
| 43 | + return fluent; |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * input specifies what the input to pass to the identified API function. |
| 48 | + * |
| 49 | + * Input fields may be specified as strings such as `'#{ANOTHER_QUERYS_NAME}'` |
| 50 | + * or `'#{ANOTHER_QUERYS_NAME}.foo.bar'`. |
| 51 | + * qryq will then identify these other queries as the current query's dependents, |
| 52 | + * and wait for them to complete execution before beginning this one. |
| 53 | + * It will also substitute the correct values from the return value of the |
| 54 | + * dependent queries. |
| 55 | + * |
| 56 | + * @param data {Object} |
| 57 | + * @return {Fluent} |
| 58 | + */ |
| 59 | + function input(data) { |
| 60 | + //TODO |
| 61 | + return fluent; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * depends specifies which other queries need to complete |
| 66 | + * execution prior to beginning executing the current one. |
| 67 | + * |
| 68 | + * This is **optional**, as if this is not specified, |
| 69 | + * qryq will parse the input object for expressions. |
| 70 | + * |
| 71 | + * @param dependIds {Array<string>} |
| 72 | + * @return {Fluent} |
| 73 | + */ |
| 74 | + function depends(dependIds) { |
| 75 | + //TODO |
| 76 | + return fluent; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * filterOutput, when called with `true`, specifies that the output of the |
| 81 | + * current query should be **excluded** from the final result returned. |
| 82 | + * |
| 83 | + * This is **optional**, as is this is not specified, |
| 84 | + * qryq simply inlcudes the results in the output by default. |
| 85 | + * |
| 86 | + * @param shouldFilter {boolean} |
| 87 | + * @return {Fluent} |
| 88 | + */ |
| 89 | + function filterOutput(shouldFilter) { |
| 90 | + //TODO |
| 91 | + return fluent; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * allQueries specifies the entire list of queries. |
| 96 | + * |
| 97 | + * This should only be called once, |
| 98 | + * and other queries should not be manually specified if this is used. |
| 99 | + * |
| 100 | + * @param {Array<GraphQuery>} |
| 101 | + * @return {Fluent} |
| 102 | + */ |
| 103 | + function allQueries(list) { |
| 104 | + //TODO |
| 105 | + return fluent; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * run finalises the list of queries and then executes them. |
| 110 | + * The promise it returns will resolve the final results of the |
| 111 | + * dependent set of queries. |
| 112 | + * |
| 113 | + * @return {Promise} |
| 114 | + */ |
| 115 | + function run() { |
| 116 | + var deferred = Q.defer(); |
| 117 | + //TODO execute graph of queries using deferred and fluent.queries |
| 118 | + return deferred.promise; |
| 119 | + } |
| 120 | + |
| 121 | + return fluent; |
| 122 | +} |
| 123 | + |
| 124 | +module.exports = qryqGraph; |
0 commit comments