postman-collection
Advanced tools
Comparing version 3.0.10 to 3.1.0-beta.1
# Postman Collection SDK Changelog | ||
#### v3.1.0-beta.1 (June 6, 2018) | ||
* Added support for tracking changes on a `VariableScope`. To use this you can enable tracking on variable scopes at the time of construction like | ||
```js | ||
var variableScope = new VariableScope(definition, layers, { enableTracking: true }); | ||
``` | ||
or at any point later using | ||
```js | ||
variableScope.enableTracking(); | ||
``` | ||
* If you are only interested in the last change for any key, you can use the `compressed` mode. This is available when you enable compression during construction as well as later. | ||
```js | ||
var variableScope = new VariableScope(definition, layers, { | ||
enableTracking: true, | ||
changeTracker: { compressed: true } | ||
}); | ||
// which would be the same as | ||
variableScope.enableTracking({ compressed: true }); | ||
``` | ||
* This makes sure that you are only provided with the most minimal set of changes. Use this when you are conscious about memory usage and performance while applying the changes back. | ||
* The diff object allows you to then apply the same changes on a different `VariableScope`. | ||
```js | ||
var scope1 = new VariableScope(definition, layers, { enableTracking: true }), | ||
scope2 = new VariableScope(); | ||
// this change is captured in scope1.changes | ||
scope1.set('foo', 'bar'); | ||
// this applies the captured changes on scope2 | ||
scope2.patch(scope1.changes); | ||
// which is the same as | ||
scope1.changes.apply(scope2); | ||
``` | ||
* **Warning:** These public API are still being worked upon. Expect some breaking changes before the final stable release. | ||
#### v3.0.10 (May 22, 2018) | ||
@@ -4,0 +48,0 @@ * Revert computing filename from content-disposition header in `Response~mime` |
@@ -5,3 +5,6 @@ var _ = require('../util').lodash, | ||
VariableList = require('./variable-list').VariableList, | ||
VariableScopeDiff = require('./variable-scope-diff').VariableScopeDiff, | ||
COMPRESSED = 'compressed', | ||
VariableScope; | ||
@@ -61,3 +64,3 @@ | ||
*/ | ||
VariableScope = function PostmanVariableScope (definition, layers) { | ||
VariableScope = function PostmanVariableScope (definition, layers, options) { | ||
// in case the definition is an array (legacy format) or existing as list, we convert to actual format | ||
@@ -94,2 +97,12 @@ if (_.isArray(definition) || VariableList.isVariableList(definition)) { | ||
} | ||
// recreate the diff if present in the definition | ||
if (definition && definition.changes) { | ||
this.diff = new VariableScopeDiff(definition.changes); | ||
} | ||
// enable tracking only if configured | ||
if (options && options.enableTracking) { | ||
this.enableTracking(options.changeTracker); | ||
} | ||
}), Property); | ||
@@ -211,5 +224,10 @@ | ||
// If a variable by the name key exists, update it's value and return. | ||
if (variable) { return variable.update(update); } | ||
if (variable) { | ||
variable.update(update); | ||
} | ||
else { | ||
this.values.add(update); | ||
} | ||
this.values.add(update); | ||
this._postman_enableTracking && this.changes.track('set', key, value); | ||
}, | ||
@@ -223,3 +241,11 @@ | ||
unset: function (key) { | ||
if (!(key && this.values.has(key))) { | ||
return; | ||
} | ||
this.values.remove(key); | ||
if (this._postman_enableTracking) { | ||
this.changes.track('unset', key); | ||
} | ||
}, | ||
@@ -231,2 +257,9 @@ | ||
clear: function () { | ||
if (this._postman_enableTracking) { | ||
// track clear as delete for each key | ||
this.values.each(function (variable) { | ||
this.changes.track('unset', variable.key); | ||
}.bind(this)); | ||
} | ||
this.values.clear(); | ||
@@ -236,2 +269,25 @@ }, | ||
/** | ||
* Enables change tracking on the variable scope. Changes are tracked on the `changes` attribute. | ||
*/ | ||
enableTracking: function (options) { | ||
this._postman_enableTracking = true; | ||
var compress = options && options.compressed, | ||
diffDefinition; | ||
// if there are changes already wipe them | ||
if (this.changes) { | ||
this.changes.reset(); | ||
// adjust mode based on options | ||
compress && this.changes.compress(); | ||
} | ||
compress && (diffDefinition = { mode: COMPRESSED }); | ||
// otherwise instantiate a new change tracker | ||
this.changes = new VariableScopeDiff(diffDefinition); | ||
}, | ||
/** | ||
* Using this function, one can sync the values of this variable list from a reference object. | ||
@@ -297,2 +353,16 @@ * | ||
this._layers.push(list); | ||
}, | ||
/** | ||
* Applies a set of variable diff on the scope. | ||
* | ||
* @param {VariableScopeDiff} diff | ||
*/ | ||
patch (diff) { | ||
if (!diff) { | ||
return; | ||
} | ||
// @todo: add isVariableScopeDiff check here | ||
diff.apply(this); | ||
} | ||
@@ -299,0 +369,0 @@ }); |
@@ -28,4 +28,6 @@ module.exports = { | ||
Variable: require('./collection/variable').Variable, | ||
VariableChangeset: require('./collection/variable-changeset').VariableChangeset, | ||
VariableList: require('./collection/variable-list').VariableList, | ||
VariableScope: require('./collection/variable-scope').VariableScope, | ||
VariableScopeDiff: require('./collection/variable-scope-diff').VariableScopeDiff, | ||
ProxyConfig: require('./collection/proxy-config').ProxyConfig, | ||
@@ -32,0 +34,0 @@ ProxyConfigList: require('./collection/proxy-config-list').ProxyConfigList, |
@@ -5,3 +5,3 @@ { | ||
"author": "Postman Labs <help@getpostman.com>", | ||
"version": "3.0.10", | ||
"version": "3.1.0-beta.1", | ||
"keywords": [ | ||
@@ -56,3 +56,3 @@ "postman" | ||
"eslint": "4.19.1", | ||
"eslint-plugin-jsdoc": "3.7.0", | ||
"eslint-plugin-jsdoc": "3.7.1", | ||
"eslint-plugin-lodash": "2.7.0", | ||
@@ -63,3 +63,3 @@ "eslint-plugin-mocha": "4.12.0", | ||
"istanbul": "0.4.5", | ||
"js-yaml": "3.11.0", | ||
"js-yaml": "3.12.0", | ||
"jsdoc": "3.5.5", | ||
@@ -66,0 +66,0 @@ "jsdoc-to-markdown": "4.0.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
440730
74
9559
1