|
|
10 |
__coverage__['build/dataschema-json/dataschema-json.js'] = {"path":"build/dataschema-json/dataschema-json.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0],"19":[0,0],"20":[0,0],"21":[0,0],"22":[0,0],"23":[0,0],"24":[0,0],"25":[0,0],"26":[0,0],"27":[0,0],"28":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":46}}},"2":{"name":"(anonymous_2)","line":44,"loc":{"start":{"line":44,"column":13},"end":{"line":44,"column":31}}},"3":{"name":"(anonymous_3)","line":56,"loc":{"start":{"line":56,"column":16},"end":{"line":56,"column":35}}},"4":{"name":"(anonymous_4)","line":58,"loc":{"start":{"line":58,"column":16},"end":{"line":58,"column":32}}},"5":{"name":"(anonymous_5)","line":88,"loc":{"start":{"line":88,"column":22},"end":{"line":88,"column":44}}},"6":{"name":"(anonymous_6)","line":221,"loc":{"start":{"line":221,"column":11},"end":{"line":221,"column":34}}},"7":{"name":"(anonymous_7)","line":263,"loc":{"start":{"line":263,"column":19},"end":{"line":263,"column":55}}},"8":{"name":"(anonymous_8)","line":303,"loc":{"start":{"line":303,"column":21},"end":{"line":303,"column":58}}},"9":{"name":"(anonymous_9)","line":416,"loc":{"start":{"line":416,"column":16},"end":{"line":416,"column":56}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":439,"column":56}},"2":{"start":{"line":19,"column":0},"end":{"line":27,"column":15}},"3":{"start":{"line":29,"column":0},"end":{"line":433,"column":2}},"4":{"start":{"line":45,"column":8},"end":{"line":47,"column":18}},"5":{"start":{"line":49,"column":8},"end":{"line":75,"column":9}},"6":{"start":{"line":54,"column":12},"end":{"line":59,"column":34}},"7":{"start":{"line":56,"column":36},"end":{"line":56,"column":47}},"8":{"start":{"line":56,"column":47},"end":{"line":56,"column":65}},"9":{"start":{"line":58,"column":33},"end":{"line":58,"column":59}},"10":{"start":{"line":58,"column":59},"end":{"line":58,"column":77}},"11":{"start":{"line":65,"column":12},"end":{"line":65,"column":38}},"12":{"start":{"line":66,"column":12},"end":{"line":70,"column":13}},"13":{"start":{"line":67,"column":16},"end":{"line":69,"column":17}},"14":{"start":{"line":68,"column":20},"end":{"line":68,"column":67}},"15":{"start":{"line":76,"column":8},"end":{"line":76,"column":20}},"16":{"start":{"line":89,"column":8},"end":{"line":90,"column":30}},"17":{"start":{"line":91,"column":8},"end":{"line":98,"column":9}},"18":{"start":{"line":92,"column":12},"end":{"line":97,"column":13}},"19":{"start":{"line":93,"column":16},"end":{"line":93,"column":37}},"20":{"start":{"line":95,"column":16},"end":{"line":95,"column":33}},"21":{"start":{"line":96,"column":16},"end":{"line":96,"column":22}},"22":{"start":{"line":99,"column":8},"end":{"line":99,"column":20}},"23":{"start":{"line":222,"column":8},"end":{"line":223,"column":49}},"24":{"start":{"line":226,"column":8},"end":{"line":234,"column":9}},"25":{"start":{"line":227,"column":12},"end":{"line":233,"column":13}},"26":{"start":{"line":228,"column":16},"end":{"line":228,"column":45}},"27":{"start":{"line":231,"column":16},"end":{"line":231,"column":35}},"28":{"start":{"line":232,"column":16},"end":{"line":232,"column":32}},"29":{"start":{"line":236,"column":8},"end":{"line":247,"column":9}},"30":{"start":{"line":238,"column":12},"end":{"line":238,"column":86}},"31":{"start":{"line":241,"column":12},"end":{"line":243,"column":13}},"32":{"start":{"line":242,"column":16},"end":{"line":242,"column":87}},"33":{"start":{"line":246,"column":12},"end":{"line":246,"column":68}},"34":{"start":{"line":249,"column":8},"end":{"line":249,"column":24}},"35":{"start":{"line":264,"column":8},"end":{"line":272,"column":32}},"36":{"start":{"line":274,"column":8},"end":{"line":287,"column":9}},"37":{"start":{"line":279,"column":12},"end":{"line":283,"column":13}},"38":{"start":{"line":280,"column":16},"end":{"line":280,"column":105}},"39":{"start":{"line":282,"column":16},"end":{"line":282,"column":43}},"40":{"start":{"line":284,"column":15},"end":{"line":287,"column":9}},"41":{"start":{"line":285,"column":12},"end":{"line":285,"column":34}},"42":{"start":{"line":286,"column":12},"end":{"line":286,"column":73}},"43":{"start":{"line":289,"column":8},"end":{"line":289,"column":24}},"44":{"start":{"line":304,"column":8},"end":{"line":309,"column":27}},"45":{"start":{"line":312,"column":8},"end":{"line":347,"column":9}},"46":{"start":{"line":313,"column":12},"end":{"line":313,"column":30}},"47":{"start":{"line":314,"column":12},"end":{"line":314,"column":37}},"48":{"start":{"line":315,"column":12},"end":{"line":315,"column":43}},"49":{"start":{"line":318,"column":12},"end":{"line":318,"column":47}},"50":{"start":{"line":319,"column":12},"end":{"line":333,"column":13}},"51":{"start":{"line":320,"column":16},"end":{"line":331,"column":17}},"52":{"start":{"line":321,"column":20},"end":{"line":324,"column":23}},"53":{"start":{"line":326,"column":20},"end":{"line":330,"column":23}},"54":{"start":{"line":337,"column":12},"end":{"line":339,"column":53}},"55":{"start":{"line":341,"column":12},"end":{"line":346,"column":13}},"56":{"start":{"line":342,"column":16},"end":{"line":345,"column":19}},"57":{"start":{"line":351,"column":8},"end":{"line":400,"column":9}},"58":{"start":{"line":352,"column":12},"end":{"line":352,"column":24}},"59":{"start":{"line":353,"column":12},"end":{"line":353,"column":33}},"60":{"start":{"line":354,"column":12},"end":{"line":399,"column":13}},"61":{"start":{"line":356,"column":16},"end":{"line":378,"column":17}},"62":{"start":{"line":357,"column":20},"end":{"line":357,"column":43}},"63":{"start":{"line":358,"column":20},"end":{"line":358,"column":73}},"64":{"start":{"line":359,"column":20},"end":{"line":374,"column":21}},"65":{"start":{"line":360,"column":24},"end":{"line":360,"column":82}},"66":{"start":{"line":364,"column":24},"end":{"line":373,"column":25}},"67":{"start":{"line":365,"column":28},"end":{"line":368,"column":31}},"68":{"start":{"line":371,"column":28},"end":{"line":371,"column":53}},"69":{"start":{"line":372,"column":28},"end":{"line":372,"column":37}},"70":{"start":{"line":376,"column":20},"end":{"line":377,"column":80}},"71":{"start":{"line":381,"column":16},"end":{"line":387,"column":17}},"72":{"start":{"line":382,"column":20},"end":{"line":382,"column":42}},"73":{"start":{"line":384,"column":20},"end":{"line":386,"column":66}},"74":{"start":{"line":390,"column":16},"end":{"line":397,"column":17}},"75":{"start":{"line":391,"column":20},"end":{"line":391,"column":46}},"76":{"start":{"line":392,"column":20},"end":{"line":392,"column":81}},"77":{"start":{"line":394,"column":20},"end":{"line":396,"column":21}},"78":{"start":{"line":395,"column":24},"end":{"line":395,"column":43}},"79":{"start":{"line":398,"column":16},"end":{"line":398,"column":36}},"80":{"start":{"line":401,"column":8},"end":{"line":401,"column":35}},"81":{"start":{"line":402,"column":8},"end":{"line":402,"column":24}},"82":{"start":{"line":417,"column":8},"end":{"line":430,"column":9}},"83":{"start":{"line":418,"column":12},"end":{"line":418,"column":26}},"84":{"start":{"line":419,"column":12},"end":{"line":426,"column":13}},"85":{"start":{"line":420,"column":16},"end":{"line":425,"column":17}},"86":{"start":{"line":421,"column":20},"end":{"line":421,"column":63}},"87":{"start":{"line":422,"column":20},"end":{"line":424,"column":21}},"88":{"start":{"line":423,"column":24},"end":{"line":423,"column":88}},"89":{"start":{"line":429,"column":12},"end":{"line":429,"column":75}},"90":{"start":{"line":431,"column":8},"end":{"line":431,"column":24}},"91":{"start":{"line":436,"column":0},"end":{"line":436,"column":44}}},"branchMap":{"1":{"line":49,"type":"if","locations":[{"start":{"line":49,"column":8},"end":{"line":49,"column":8}},{"start":{"line":49,"column":8},"end":{"line":49,"column":8}}]},"2":{"line":67,"type":"if","locations":[{"start":{"line":67,"column":16},"end":{"line":67,"column":16}},{"start":{"line":67,"column":16},"end":{"line":67,"column":16}}]},"3":{"line":92,"type":"if","locations":[{"start":{"line":92,"column":12},"end":{"line":92,"column":12}},{"start":{"line":92,"column":12},"end":{"line":92,"column":12}}]},"4":{"line":92,"type":"binary-expr","locations":[{"start":{"line":92,"column":16},"end":{"line":92,"column":30}},{"start":{"line":92,"column":35},"end":{"line":92,"column":50}}]},"5":{"line":226,"type":"if","locations":[{"start":{"line":226,"column":8},"end":{"line":226,"column":8}},{"start":{"line":226,"column":8},"end":{"line":226,"column":8}}]},"6":{"line":236,"type":"if","locations":[{"start":{"line":236,"column":8},"end":{"line":236,"column":8}},{"start":{"line":236,"column":8},"end":{"line":236,"column":8}}]},"7":{"line":236,"type":"binary-expr","locations":[{"start":{"line":236,"column":12},"end":{"line":236,"column":29}},{"start":{"line":236,"column":33},"end":{"line":236,"column":39}}]},"8":{"line":241,"type":"if","locations":[{"start":{"line":241,"column":12},"end":{"line":241,"column":12}},{"start":{"line":241,"column":12},"end":{"line":241,"column":12}}]},"9":{"line":267,"type":"cond-expr","locations":[{"start":{"line":268,"column":25},"end":{"line":270,"column":61}},{"start":{"line":272,"column":24},"end":{"line":272,"column":31}}]},"10":{"line":268,"type":"binary-expr","locations":[{"start":{"line":268,"column":25},"end":{"line":268,"column":48}},{"start":{"line":270,"column":28},"end":{"line":270,"column":61}}]},"11":{"line":274,"type":"if","locations":[{"start":{"line":274,"column":8},"end":{"line":274,"column":8}},{"start":{"line":274,"column":8},"end":{"line":274,"column":8}}]},"12":{"line":279,"type":"if","locations":[{"start":{"line":279,"column":12},"end":{"line":279,"column":12}},{"start":{"line":279,"column":12},"end":{"line":279,"column":12}}]},"13":{"line":284,"type":"if","locations":[{"start":{"line":284,"column":15},"end":{"line":284,"column":15}},{"start":{"line":284,"column":15},"end":{"line":284,"column":15}}]},"14":{"line":314,"type":"binary-expr","locations":[{"start":{"line":314,"column":18},"end":{"line":314,"column":27}},{"start":{"line":314,"column":31},"end":{"line":314,"column":36}}]},"15":{"line":315,"type":"binary-expr","locations":[{"start":{"line":315,"column":22},"end":{"line":315,"column":35}},{"start":{"line":315,"column":39},"end":{"line":315,"column":42}}]},"16":{"line":319,"type":"if","locations":[{"start":{"line":319,"column":12},"end":{"line":319,"column":12}},{"start":{"line":319,"column":12},"end":{"line":319,"column":12}}]},"17":{"line":320,"type":"if","locations":[{"start":{"line":320,"column":16},"end":{"line":320,"column":16}},{"start":{"line":320,"column":16},"end":{"line":320,"column":16}}]},"18":{"line":337,"type":"cond-expr","locations":[{"start":{"line":338,"column":24},"end":{"line":338,"column":36}},{"start":{"line":339,"column":24},"end":{"line":339,"column":52}}]},"19":{"line":341,"type":"if","locations":[{"start":{"line":341,"column":12},"end":{"line":341,"column":12}},{"start":{"line":341,"column":12},"end":{"line":341,"column":12}}]},"20":{"line":354,"type":"if","locations":[{"start":{"line":354,"column":12},"end":{"line":354,"column":12}},{"start":{"line":354,"column":12},"end":{"line":354,"column":12}}]},"21":{"line":359,"type":"if","locations":[{"start":{"line":359,"column":20},"end":{"line":359,"column":20}},{"start":{"line":359,"column":20},"end":{"line":359,"column":20}}]},"22":{"line":364,"type":"if","locations":[{"start":{"line":364,"column":24},"end":{"line":364,"column":24}},{"start":{"line":364,"column":24},"end":{"line":364,"column":24}}]},"23":{"line":385,"type":"cond-expr","locations":[{"start":{"line":386,"column":28},"end":{"line":386,"column":37}},{"start":{"line":386,"column":40},"end":{"line":386,"column":57}}]},"24":{"line":394,"type":"if","locations":[{"start":{"line":394,"column":20},"end":{"line":394,"column":20}},{"start":{"line":394,"column":20},"end":{"line":394,"column":20}}]},"25":{"line":417,"type":"if","locations":[{"start":{"line":417,"column":8},"end":{"line":417,"column":8}},{"start":{"line":417,"column":8},"end":{"line":417,"column":8}}]},"26":{"line":420,"type":"if","locations":[{"start":{"line":420,"column":16},"end":{"line":420,"column":16}},{"start":{"line":420,"column":16},"end":{"line":420,"column":16}}]},"27":{"line":422,"type":"if","locations":[{"start":{"line":422,"column":20},"end":{"line":422,"column":20}},{"start":{"line":422,"column":20},"end":{"line":422,"column":20}}]},"28":{"line":422,"type":"binary-expr","locations":[{"start":{"line":422,"column":24},"end":{"line":422,"column":28}},{"start":{"line":422,"column":32},"end":{"line":422,"column":39}}]}},"code":["(function () { YUI.add('dataschema-json', function (Y, NAME) {","","/**","Provides a DataSchema implementation which can be used to work with JSON data.","","@module dataschema","@submodule dataschema-json","**/","","/**","Provides a DataSchema implementation which can be used to work with JSON data.","","See the `apply` method for usage.","","@class DataSchema.JSON","@extends DataSchema.Base","@static","**/","var LANG = Y.Lang,"," isFunction = LANG.isFunction,"," isObject = LANG.isObject,"," isArray = LANG.isArray,"," // TODO: I don't think the calls to Base.* need to be done via Base since"," // Base is mixed into SchemaJSON. Investigate for later."," Base = Y.DataSchema.Base,",""," SchemaJSON;"," ","SchemaJSON = {","","/////////////////////////////////////////////////////////////////////////////","//","// DataSchema.JSON static methods","//","/////////////////////////////////////////////////////////////////////////////"," /**"," * Utility function converts JSON locator strings into walkable paths"," *"," * @method getPath"," * @param locator {String} JSON value locator."," * @return {String[]} Walkable path to data value."," * @static"," */"," getPath: function(locator) {"," var path = null,"," keys = [],"," i = 0;",""," if (locator) {"," // Strip the [\"string keys\"] and [1] array indexes"," // TODO: the first two steps can probably be reduced to one with"," // /\\[\\s*(['\"])?(.*?)\\1\\s*\\]/g, but the array indices would be"," // stored as strings. This is not likely an issue."," locator = locator."," replace(/\\[\\s*(['\"])(.*?)\\1\\s*\\]/g,"," function (x,$1,$2) {keys[i]=$2;return '.@'+(i++);})."," replace(/\\[(\\d+)\\]/g,"," function (x,$1) {keys[i]=parseInt($1,10)|0;return '.@'+(i++);})."," replace(/^\\./,''); // remove leading dot",""," // Validate against problematic characters."," // commented out because the path isn't sent to eval, so it"," // should be safe. I'm not sure what makes a locator invalid."," //if (!/[^\\w\\.\\$@]/.test(locator)) {"," path = locator.split('.');"," for (i=path.length-1; i >= 0; --i) {"," if (path[i].charAt(0) === '@') {"," path[i] = keys[parseInt(path[i].substr(1),10)];"," }"," }"," /*}"," else {"," }"," */"," }"," return path;"," },",""," /**"," * Utility function to walk a path and return the value located there."," *"," * @method getLocationValue"," * @param path {String[]} Locator path."," * @param data {String} Data to traverse."," * @return {Object} Data value at location."," * @static"," */"," getLocationValue: function (path, data) {"," var i = 0,"," len = path.length;"," for (;i<len;i++) {"," if (isObject(data) && (path[i] in data)) {"," data = data[path[i]];"," } else {"," data = undefined;"," break;"," }"," }"," return data;"," },",""," /**"," Applies a schema to an array of data located in a JSON structure, returning"," a normalized object with results in the `results` property. Additional"," information can be parsed out of the JSON for inclusion in the `meta`"," property of the response object. If an error is encountered during"," processing, an `error` property will be added.",""," The input _data_ is expected to be an object or array. If it is a string,"," it will be passed through `Y.JSON.parse()`.",""," If _data_ contains an array of data records to normalize, specify the"," _schema.resultListLocator_ as a dot separated path string just as you would"," reference it in JavaScript. So if your _data_ object has a record array at"," _data.response.results_, use _schema.resultListLocator_ ="," \"response.results\". Bracket notation can also be used for array indices or"," object properties (e.g. \"response['results']\"); This is called a \"path"," locator\"",""," Field data in the result list is extracted with field identifiers in"," _schema.resultFields_. Field identifiers are objects with the following"," properties:",""," * `key` : <strong>(required)</strong> The path locator (String)"," * `parser`: A function or the name of a function on `Y.Parsers` used"," to convert the input value into a normalized type. Parser"," functions are passed the value as input and are expected to"," return a value.",""," If no value parsing is needed, you can use path locators (strings) "," instead of field identifiers (objects) -- see example below.",""," If no processing of the result list array is needed, _schema.resultFields_"," can be omitted; the `response.results` will point directly to the array.",""," If the result list contains arrays, `response.results` will contain an"," array of objects with key:value pairs assuming the fields in"," _schema.resultFields_ are ordered in accordance with the data array"," values.",""," If the result list contains objects, the identified _schema.resultFields_"," will be used to extract a value from those objects for the output result.",""," To extract additional information from the JSON, include an array of"," path locators in _schema.metaFields_. The collected values will be"," stored in `response.meta`.","",""," @example"," // Process array of arrays"," var schema = {"," resultListLocator: 'produce.fruit',"," resultFields: [ 'name', 'color' ]"," },"," data = {"," produce: {"," fruit: ["," [ 'Banana', 'yellow' ],"," [ 'Orange', 'orange' ],"," [ 'Eggplant', 'purple' ]"," ]"," }"," };",""," var response = Y.DataSchema.JSON.apply(schema, data);",""," // response.results[0] is { name: \"Banana\", color: \"yellow\" }",""," "," // Process array of objects + some metadata"," schema.metaFields = [ 'lastInventory' ];",""," data = {"," produce: {"," fruit: ["," { name: 'Banana', color: 'yellow', price: '1.96' },"," { name: 'Orange', color: 'orange', price: '2.04' },"," { name: 'Eggplant', color: 'purple', price: '4.31' }"," ]"," },"," lastInventory: '2011-07-19'"," };",""," response = Y.DataSchema.JSON.apply(schema, data);",""," // response.results[0] is { name: \"Banana\", color: \"yellow\" }"," // response.meta.lastInventory is '2001-07-19'","",""," // Use parsers"," schema.resultFields = ["," {"," key: 'name',"," parser: function (val) { return val.toUpperCase(); }"," },"," {"," key: 'price',"," parser: 'number' // Uses Y.Parsers.number"," }"," ];",""," response = Y.DataSchema.JSON.apply(schema, data);",""," // Note price was converted from a numeric string to a number"," // response.results[0] looks like { fruit: \"BANANA\", price: 1.96 }"," "," @method apply"," @param {Object} [schema] Schema to apply. Supported configuration"," properties are:"," @param {String} [schema.resultListLocator] Path locator for the"," location of the array of records to flatten into `response.results`"," @param {Array} [schema.resultFields] Field identifiers to"," locate/assign values in the response records. See above for"," details."," @param {Array} [schema.metaFields] Path locators to extract extra"," non-record related information from the data object."," @param {Object|Array|String} data JSON data or its string serialization."," @return {Object} An Object with properties `results` and `meta`"," @static"," **/"," apply: function(schema, data) {"," var data_in = data,"," data_out = { results: [], meta: {} };",""," // Convert incoming JSON strings"," if (!isObject(data)) {"," try {"," data_in = Y.JSON.parse(data);"," }"," catch(e) {"," data_out.error = e;"," return data_out;"," }"," }",""," if (isObject(data_in) && schema) {"," // Parse results data"," data_out = SchemaJSON._parseResults.call(this, schema, data_in, data_out);",""," // Parse meta data"," if (schema.metaFields !== undefined) {"," data_out = SchemaJSON._parseMeta(schema.metaFields, data_in, data_out);"," }"," }"," else {"," data_out.error = new Error(\"JSON schema parse failure\");"," }",""," return data_out;"," },",""," /**"," * Schema-parsed list of results from full data"," *"," * @method _parseResults"," * @param schema {Object} Schema to parse against."," * @param json_in {Object} JSON to parse."," * @param data_out {Object} In-progress parsed data to update."," * @return {Object} Parsed data object."," * @static"," * @protected"," */"," _parseResults: function(schema, json_in, data_out) {"," var getPath = SchemaJSON.getPath,"," getValue = SchemaJSON.getLocationValue,"," path = getPath(schema.resultListLocator),"," results = path ?"," (getValue(path, json_in) ||"," // Fall back to treat resultListLocator as a simple key"," json_in[schema.resultListLocator]) :"," // Or if no resultListLocator is supplied, use the input"," json_in;",""," if (isArray(results)) {"," // if no result fields are passed in, then just take"," // the results array whole-hog Sometimes you're getting"," // an array of strings, or want the whole object, so"," // resultFields don't make sense."," if (isArray(schema.resultFields)) {"," data_out = SchemaJSON._getFieldValues.call(this, schema.resultFields, results, data_out);"," } else {"," data_out.results = results;"," }"," } else if (schema.resultListLocator) {"," data_out.results = [];"," data_out.error = new Error(\"JSON results retrieval failure\");"," }",""," return data_out;"," },",""," /**"," * Get field data values out of list of full results"," *"," * @method _getFieldValues"," * @param fields {Array} Fields to find."," * @param array_in {Array} Results to parse."," * @param data_out {Object} In-progress parsed data to update."," * @return {Object} Parsed data object."," * @static"," * @protected"," */"," _getFieldValues: function(fields, array_in, data_out) {"," var results = [],"," len = fields.length,"," i, j,"," field, key, locator, path, parser, val,"," simplePaths = [], complexPaths = [], fieldParsers = [],"," result, record;",""," // First collect hashes of simple paths, complex paths, and parsers"," for (i=0; i<len; i++) {"," field = fields[i]; // A field can be a simple string or a hash"," key = field.key || field; // Find the key"," locator = field.locator || key; // Find the locator",""," // Validate and store locators for later"," path = SchemaJSON.getPath(locator);"," if (path) {"," if (path.length === 1) {"," simplePaths.push({"," key : key,"," path: path[0]"," });"," } else {"," complexPaths.push({"," key : key,"," path : path,"," locator: locator"," });"," }"," } else {"," }",""," // Validate and store parsers for later"," //TODO: use Y.DataSchema.parse?"," parser = (isFunction(field.parser)) ?"," field.parser :"," Y.Parsers[field.parser + ''];",""," if (parser) {"," fieldParsers.push({"," key : key,"," parser: parser"," });"," }"," }",""," // Traverse list of array_in, creating records of simple fields,"," // complex fields, and applying parsers as necessary"," for (i=array_in.length-1; i>=0; --i) {"," record = {};"," result = array_in[i];"," if(result) {"," // Cycle through complexLocators"," for (j=complexPaths.length - 1; j>=0; --j) {"," path = complexPaths[j];"," val = SchemaJSON.getLocationValue(path.path, result);"," if (val === undefined) {"," val = SchemaJSON.getLocationValue([path.locator], result);"," // Fail over keys like \"foo.bar\" from nested parsing"," // to single token parsing if a value is found in"," // results[\"foo.bar\"]"," if (val !== undefined) {"," simplePaths.push({"," key: path.key,"," path: path.locator"," });"," // Don't try to process the path as complex"," // for further results"," complexPaths.splice(i,1);"," continue;"," }"," }",""," record[path.key] = Base.parse.call(this,"," (SchemaJSON.getLocationValue(path.path, result)), path);"," }",""," // Cycle through simpleLocators"," for (j = simplePaths.length - 1; j >= 0; --j) {"," path = simplePaths[j];"," // Bug 1777850: The result might be an array instead of object"," record[path.key] = Base.parse.call(this,"," ((result[path.path] === undefined) ?"," result[j] : result[path.path]), path);"," }",""," // Cycle through fieldParsers"," for (j=fieldParsers.length-1; j>=0; --j) {"," key = fieldParsers[j].key;"," record[key] = fieldParsers[j].parser.call(this, record[key]);"," // Safety net"," if (record[key] === undefined) {"," record[key] = null;"," }"," }"," results[i] = record;"," }"," }"," data_out.results = results;"," return data_out;"," },",""," /**"," * Parses results data according to schema"," *"," * @method _parseMeta"," * @param metaFields {Object} Metafields definitions."," * @param json_in {Object} JSON to parse."," * @param data_out {Object} In-progress parsed data to update."," * @return {Object} Schema-parsed meta data."," * @static"," * @protected"," */"," _parseMeta: function(metaFields, json_in, data_out) {"," if (isObject(metaFields)) {"," var key, path;"," for(key in metaFields) {"," if (metaFields.hasOwnProperty(key)) {"," path = SchemaJSON.getPath(metaFields[key]);"," if (path && json_in) {"," data_out.meta[key] = SchemaJSON.getLocationValue(path, json_in);"," }"," }"," }"," }"," else {"," data_out.error = new Error(\"JSON meta data retrieval failure\");"," }"," return data_out;"," }","};","","// TODO: Y.Object + mix() might be better here","Y.DataSchema.JSON = Y.mix(SchemaJSON, Base);","","","}, '3.10.3', {\"requires\": [\"dataschema-base\", \"json\"]});","","}());"]}; |