postman-collection
Advanced tools
Comparing version 3.4.7-beta.1 to 3.4.7-beta.2
var _ = require('../util').lodash, | ||
PropertyBase = require('./property-base').PropertyBase, | ||
PropertyList = require('./property-list').PropertyList, | ||
VariableList = require('./variable-list').VariableList, | ||
QueryParam = require('./query-param').QueryParam, | ||
FormParam = require('./form-param').FormParam, | ||
RequestBody, | ||
EMPTY = '', | ||
EMPTY = ''; | ||
RequestBody; | ||
@@ -43,4 +42,4 @@ _.inherit(( | ||
urlencoded = options.urlencoded, | ||
transform = options.transform, | ||
formdata = options.formdata, | ||
graphql = options.graphql, | ||
file = options.file, | ||
@@ -52,3 +51,6 @@ raw = options.raw; | ||
_.isString(options.urlencoded) && (urlencoded = QueryParam.parse(options.urlencoded)); | ||
urlencoded = new PropertyList(QueryParam, this, urlencoded); | ||
// @todo: The fallback in the ternary expression will never be hit, as urlencoded points to | ||
// @todo: options.urlencoded | ||
urlencoded = urlencoded ? new PropertyList(QueryParam, this, urlencoded) : | ||
new PropertyList(QueryParam, this, []); | ||
} | ||
@@ -58,25 +60,19 @@ | ||
if (options.formdata) { | ||
formdata = new PropertyList(FormParam, this, formdata); | ||
// @todo: The fallback in the ternary expression will never be hit, as formdata points to | ||
// @todo: options.formdata | ||
formdata = formdata ? new PropertyList(FormParam, this, options.formdata) : | ||
new PropertyList(FormParam, this, []); | ||
} | ||
// Handle File | ||
if (_.isString(options.file)) { | ||
// @todo Variable#type file ? | ||
file = { src: options.file }; | ||
} | ||
// Handle Transform mode data | ||
// @todo add tests | ||
if (options.transform) { | ||
transform = { | ||
// @todo bail out if type is empty? | ||
type: transform.type, | ||
version: transform.version, | ||
content: transform.content || EMPTY, | ||
params: transform.params || {}, | ||
// @todo add Variable#type `file` | ||
resources: new VariableList(this, transform.resources || []) | ||
// Handle GraphQL data | ||
if (options.graphql) { | ||
graphql = { | ||
query: graphql.query || EMPTY, | ||
operationName: graphql.operationName || undefined, | ||
variables: graphql.variables | ||
}; | ||
} | ||
_.isString(options.file) && (file = { src: file }); | ||
// If mode is raw but options does not give raw content, set it to empty string | ||
@@ -88,5 +84,8 @@ (mode === RequestBody.MODES.raw && !raw) && (raw = ''); | ||
// If mode is urlencoded but options does not provide any content, set it to an empty property list | ||
// If mode is formdata but options does not provide any content, set it to an empty property list | ||
(mode === RequestBody.MODES.formdata && !formdata) && (formdata = new PropertyList(FormParam, this, [])); | ||
// If mode is graphql but options does not provide any content, set empty query | ||
(mode === RequestBody.MODES.graphql && !graphql) && (graphql = { query: EMPTY }); | ||
_.assign(this, /** @lends RequestBody.prototype */ { | ||
@@ -132,7 +131,7 @@ | ||
/** | ||
* Transform data properties for this request are held in this field. | ||
* If the request has raw graphql data associated with it, the data is held in this field. | ||
* | ||
* @type {Object} | ||
*/ | ||
transform: transform, | ||
graphql: graphql, | ||
@@ -157,10 +156,6 @@ /** | ||
if (this.mode === RequestBody.MODES.formdata || this.mode === RequestBody.MODES.file) { | ||
// @todo formdata structure is predictable (boundary, part headers) | ||
// @todo for files, clone ReadStream? | ||
// @todo: implement this, check if we need to return undefined or something. | ||
return EMPTY; | ||
} | ||
// Transform. @formdata Am I a Joke To You? (;-_-) | ||
if (this.mode === RequestBody.MODES.transform) { | ||
return EMPTY; | ||
} | ||
if (this.mode === RequestBody.MODES.urlencoded) { | ||
@@ -174,2 +169,3 @@ return PropertyList.isPropertyList(this.urlencoded) ? QueryParam.unparse(this.urlencoded.all()) : | ||
} | ||
return EMPTY; | ||
@@ -187,13 +183,18 @@ }, | ||
// Handle file mode. | ||
// bail out if there's no data for the selected mode | ||
if (!data) { | ||
return true; | ||
} | ||
// Handle file mode | ||
if (mode === RequestBody.MODES.file) { | ||
return !(data && (data.src || data.content)); | ||
return !(data.src || data.content); | ||
} | ||
// Handle transform mode. | ||
if (mode === RequestBody.MODES.transform) { | ||
return !(data && data.type); | ||
// Handle graphql mode, send empty query anyways | ||
if (mode === RequestBody.MODES.graphql) { | ||
return !data; | ||
} | ||
return !data || !(_.isString(data) ? data.length : (_.isFunction(data.count) && data.count())); | ||
return !(_.isString(data) ? data.length : (_.isFunction(data.count) && data.count())); | ||
} | ||
@@ -217,4 +218,4 @@ }); | ||
formdata: 'formdata', | ||
graphql: 'graphql', | ||
raw: 'raw', | ||
transform: 'transform', | ||
urlencoded: 'urlencoded' | ||
@@ -221,0 +222,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Postman Labs <help@getpostman.com>", | ||
"version": "3.4.7-beta.1", | ||
"version": "3.4.7-beta.2", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "postman" |
495788
10591