-
Notifications
You must be signed in to change notification settings - Fork 36
/
treema-utils.js.map
1 lines (1 loc) · 11.3 KB
/
treema-utils.js.map
1
{"version":3,"sources":["src/utils.coffee"],"names":[],"mappings":"AAAA;;AAAA,GAAc,MAAC,EAAf;CAEE;CAAA,EAAQ,EAAR;CAAA,CAEA,CAAyB,EAApB,GAAoB,CAAC,CAAD,MAAzB;CACE;AAA8B,CAA9B,QAAa;CACX,EAAW,CAAC,EAAZ,GAAW,CAAqB;KADlC;CAAA,CAGgB,CAAhB,GAAiC,EAAjC,CAAkC,CAAlC;CACE;CAAA,QAAY;AACZ,GAAc,CAAd,CAAe,CAAf,EAAc;CAAd;OADA;AAEA;UAAA;yBAAA;CACE,EAAQ,CAAL,CAAa,CAAhB;CACE,EAAK,EAAQ,IAAD;MADd;CAAA;SADF;CAAA;sBAH+B;CAAjC,IAAiC;CAJV,UAWvB;CAbF,EAEyB;CAFzB,CAeA,CAA0B,EAArB,GAAqB,CAAC,CAAD,OAA1B;CACE;;GAAY,GAAZ;KAAA;CAAA,CAEgB,CAAhB,GAAiC,EAAjC,CAAkC,CAAlC;CACE;AAAA,KAAmC,CAAnC,EAAc;CAAd;OAAA;CACA;CAAA;YAAA;uBAAA;CACE,GAAY,IAAZ;CAAA;SAAA;CACA,EAAmC,CAAhC,CAAgC,CAAnC,OAAG;CACD,EAAK,EAAQ,IAAD;MADd;CAGE,CAAmC,CAArB,EAAC,CAAD,IAAd,IAAc;CAAd,CACkD,CAAlC,EAAC,KAAjB,CAAgB,EAAhB,MAAgB;CADhB,EAEgB,MAAa,CAA7B;CACA,GAAG,MAAH;CACE,EAAK,EAAQ,IAAD;MADd;CAGE,EAAO,CAAP,SAAoB;CACpB,GAAG,CAAC,EAAJ;CAA+B,EAAO,CAAP;aAD/B;AAEO,CAAP,GAAG,QAAH;CAAiB,EAAO,CAAP;aAFjB;CAAA,EAGK,EAAQ,SAAD;WAZhB;SAFF;CAAA;sBAF+B;CAAjC,IAAiC;CAHT,UAqBxB;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AlB,IAAmB,KAAxB;WACE;CAAA,CAAQ,IAAP;CAAD,CAAmB,IAAP;CAAZ,CAA4B,EAA5B,EAAsB;CAAtB,CAA0C,IAAR;CAAlC,CAAuD,IAAT;CAA9C,CAAmE,GAAnE,CAA0D;CAA1D,CAAgF,GAAN;CAAU;CAhMtF,EA+LuB;AAKpB,CAAH,GAAG,CAAuB,CAAvB,KAAH;CACa,EAAQ,EAAnB,KAAU,CAAV;AAEM,IAHR,CAG2B,CAH3B,KAGQ;CACC,EAAU,GAAX,CAAN;IAJF;CAOE,UAAO;GA7MI;CAAA","file":"treema-utils.js","sourcesContent":["TreemaUtils = (->\n \n utils = {}\n \n utils.populateDefaults = (rootData, rootSchema, tv4) ->\n if rootSchema.default and not rootData\n rootData = @cloneDeep(rootSchema.default)\n \n @walk rootData, rootSchema, tv4, (path, data, schema) =>\n def = schema.default\n return unless @type(def) is 'object' and @type(data) is 'object'\n for key, value of def\n if data[key] is undefined\n data[key] = @cloneDeep(value)\n \n rootData\n \n utils.populateRequireds = (rootData, rootSchema, tv4) ->\n rootData ?= {}\n\n @walk rootData, rootSchema, tv4, (path, data, schema) =>\n return unless schema.required and @type(data) is 'object'\n for key in schema.required\n continue if data[key]?\n if schemaDefault = schema.default?[key]\n data[key] = @cloneDeep(schemaDefault)\n else\n childSchema = @getChildSchema(key, schema)\n workingSchema = @buildWorkingSchemas(childSchema, tv4)[0]\n schemaDefault = workingSchema.default\n if schemaDefault?\n data[key] = @cloneDeep(schemaDefault)\n else\n type = workingSchema.type\n if @type(type) is 'array' then type = type[0]\n if not type then type = 'string'\n data[key] = @defaultForType(type)\n\n rootData\n \n utils.walk = (data, schema, tv4, callback, path='') ->\n if not tv4\n tv4 = @getGlobalTv4().freshApi()\n tv4.addSchema('#', schema)\n tv4.addSchema(schema.id, schema) if schema.id\n \n workingSchemas = @buildWorkingSchemas(schema, tv4)\n workingSchema = @chooseWorkingSchema(data, workingSchemas, tv4)\n \n callback(path, data, workingSchema)\n \n # this actually works for both arrays and objects...\n dataType = @type(data)\n \n if dataType in ['array', 'object']\n f = (key, value) =>\n value = data[key]\n childPath = path.slice()\n childPath += '.' if childPath\n childPath += key\n childSchema = @getChildSchema(key, workingSchema)\n @walk(value, childSchema, tv4, callback, childPath)\n \n if dataType is 'array'\n for value, key in data\n f(key, value)\n else\n for key, value of data\n f(key, value)\n \n utils.getChildSchema = (key, schema) ->\n if @type(key) is 'string'\n for childKey, childSchema of schema.properties\n if childKey is key\n return childSchema \n for childKey, childSchema of schema.patternProperties\n if key.match(new RegExp(childKey))\n return childSchema\n if typeof schema.additionalProperties is 'object'\n return schema.additionalProperties \n \n if @type(key) is 'number'\n index = key\n if schema.items\n if Array.isArray(schema.items)\n if index < schema.items.length\n return schema.items[index]\n else if schema.additionalItems\n return schema.additionalItems\n else if schema.items\n return schema.items\n \n return {}\n \n # Working schemas -----------------------------------------------------------\n \n # Schemas can be flexible using combinatorial properties and references.\n # But it simplifies logic if schema props like $ref, allOf, anyOf, and oneOf\n # are flattened into a list of more straightforward user choices.\n # These simplifications are called working schemas.\n \n utils.buildWorkingSchemas = (schema, tv4) ->\n schema ?= {}\n baseSchema = @resolveReference(schema, tv4)\n return [schema] unless schema.allOf or schema.anyOf or schema.oneOf\n baseSchema = @cloneSchema(baseSchema)\n allOf = baseSchema.allOf\n anyOf = baseSchema.anyOf\n oneOf = baseSchema.oneOf\n delete baseSchema.allOf if baseSchema.allOf?\n delete baseSchema.anyOf if baseSchema.anyOf?\n delete baseSchema.oneOf if baseSchema.oneOf?\n \n if allOf?\n for schema in allOf\n @combineSchemas baseSchema, @resolveReference(schema, tv4)\n \n workingSchemas = []\n singularSchemas = []\n singularSchemas = singularSchemas.concat(anyOf) if anyOf?\n singularSchemas = singularSchemas.concat(oneOf) if oneOf?\n \n for singularSchema in singularSchemas\n singularSchema = @resolveReference(singularSchema, tv4)\n newBase = @cloneSchema(baseSchema)\n @combineSchemas(newBase, singularSchema)\n workingSchemas.push(newBase)\n \n workingSchemas = [baseSchema] if workingSchemas.length is 0\n workingSchemas\n \n utils.chooseWorkingSchema = (data, workingSchemas, tv4) ->\n return workingSchemas[0] if workingSchemas.length is 1\n tv4 ?= @getGlobalTv4()\n for schema in workingSchemas\n result = tv4.validateMultiple(data, schema)\n return schema if result.valid\n return workingSchemas[0]\n \n utils.resolveReference = (schema, tv4, scrubTitle=false) ->\n return schema unless schema.$ref?\n tv4 ?= @getGlobalTv4()\n resolved = tv4.getSchema(schema.$ref)\n unless resolved\n console.warn('could not resolve reference', schema.$ref, tv4.getMissingUris())\n resolved ?= {}\n delete resolved.title if scrubTitle and resolved.title?\n resolved\n \n utils.getGlobalTv4 = ->\n if typeof window isnt 'undefined'\n return window.tv4\n if typeof global isnt 'undefined'\n return global.tv4\n if typeof tv4 isnt 'undefined'\n return tv4\n \n # UTILITY UTILITIES\n # Normally I'd use jQuery or lodash for most of these, but this file should be completely library/context agnostic.\n # These are fairly simplified because data is assumed to not include non-plain objects.\n \n utils.cloneSchema = (schema) ->\n clone = {}\n clone[key] = value for key, value of schema\n clone\n \n utils.combineSchemas = (schema1, schema2) ->\n for key, value of schema2\n schema1[key] = value \n schema1\n \n utils.cloneDeep = (data) ->\n clone = data\n type = @type(data)\n if type is 'object'\n clone = {}\n if type is 'array'\n clone = []\n if type in ['object', 'array']\n for key, value of data\n clone[key] = @cloneDeep(value)\n return clone\n \n # http://arcturo.github.io/library/coffeescript/07_the_bad_parts.html\n utils.type = do ->\n classToType = {}\n for name in \"Boolean Number String Function Array Date RegExp Undefined Null\".split(\" \")\n classToType[\"[object \" + name + \"]\"] = name.toLowerCase()\n \n (obj) ->\n strType = Object::toString.call(obj)\n classToType[strType] or \"object\"\n\n utils.defaultForType = (type) ->\n {string:'', number:0, null: null, object: {}, integer: 0, boolean: false, array:[]}[type]\n \n # Export either to TreemaNode if it exists, or to module.exports for node\n\n if typeof TreemaNode isnt 'undefined'\n TreemaNode.utils = utils\n\n else if typeof module isnt 'undefined' and module.exports\n module.exports = utils\n \n else\n return utils\n\n)()\n"]}