(prop, mapping, parent)
| 124 | } |
| 125 | |
| 126 | function coerceMapping(prop, mapping, parent) { |
| 127 | if (Function.prototype.isPrototypeOf(mapping)) { |
| 128 | return mapping |
| 129 | } |
| 130 | |
| 131 | if (typeof mapping === 'string') { |
| 132 | mapping = { url: mapping } |
| 133 | } |
| 134 | |
| 135 | invariant(isPlainObject(mapping), 'Request for `%s` must be either a string or a plain object. Instead received %s', prop, mapping) |
| 136 | invariant(mapping.hasOwnProperty('url') || mapping.hasOwnProperty('value'), 'Request object for `%s` must have `url` (or `value`) attribute.', prop) |
| 137 | invariant(!(mapping.hasOwnProperty('url') && mapping.hasOwnProperty('value')), 'Request object for `%s` must not have both `url` and `value` attributes.', prop) |
| 138 | invariant(!(mapping.hasOwnProperty('value') && typeof mapping.value === 'function' && !mapping.hasOwnProperty('comparison')), 'Request object with functional `value` must also declare `comparison`.', mapping.value, mapping.comparison) |
| 139 | |
| 140 | checkTypes(mapping) |
| 141 | |
| 142 | if (parent) { |
| 143 | mapping.parent = parent.parent || parent |
| 144 | } |
| 145 | |
| 146 | mapping = assignDefaults(mapping, parent) |
| 147 | |
| 148 | invariant(isPlainObject(mapping.meta), 'meta for `%s` must be a plain object. Instead received %s', prop, mapping.meta) |
| 149 | |
| 150 | mapping.equals = function (that) { |
| 151 | that = that.parent || that |
| 152 | |
| 153 | if (this.comparison !== undefined) { |
| 154 | return this.comparison === that.comparison |
| 155 | } |
| 156 | |
| 157 | return [ 'value', 'url', 'method', 'headers', 'body' ].every((c) => { |
| 158 | return shallowEqual(this[c], that[c]) |
| 159 | }) |
| 160 | }.bind(mapping) |
| 161 | |
| 162 | return mapping |
| 163 | } |
| 164 | |
| 165 | function assignDefaults(mapping, parent) { |
| 166 | const rawHeaders = Object.assign({}, defaults.headers, mapping.headers) |
no test coverage detected
searching dependent graphs…