Skip to content

Commit

Permalink
Set prefix in VariableScope.definition
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Jul 29, 2024
1 parent 1627c88 commit e09a254
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unreleased:
- GH-1366 Fixed a bug where $randomAvatarImage was returning an invalid URL
chores:
- GH-1362 Updated `Request~size` to handle `downloadedBytes` property
- GH-1364 Added support for `prefix` in VariableScope

4.4.0:
date: 2024-02-28
Expand Down
31 changes: 15 additions & 16 deletions lib/collection/variable-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var _ = require('../util').lodash,
* @typedef VariableScope.definition
* @property {String} [id] ID of the scope
* @property {String} [name] A name of the scope
* @property {String} [prefix] A prefix to be used for variable names in this scope
* @property {Array.<Variable.definition>} [values] A list of variables defined in an array in form of `{name:String,
* value:String}`
*
Expand Down Expand Up @@ -140,16 +141,6 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ {
*/
_postman_propertyRequiresId: true,

/**
* Defines the prefix associated with the VariableList variables for internal use.
*
* @private
* @type {String}
*
*/
prefix: '',


/**
* @private
* @deprecated discontinued in v4.0
Expand Down Expand Up @@ -190,7 +181,9 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ {
* false otherwise
*/
has: function (key) {
var variable = this.values.oneNormalizedVariable(this.prefix + key),
key = (this.prefix || '') + key;

var variable = this.values.oneNormalizedVariable(key),
i,
ii;

Expand All @@ -213,7 +206,9 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ {
* @returns {*} The value of the specified variable across scopes.
*/
get: function (key) {
var variable = this.values.oneNormalizedVariable(this.prefix + key),
key = (this.prefix || '') + key;

var variable = this.values.oneNormalizedVariable(key),
i,
ii;

Expand All @@ -236,10 +231,12 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ {
* @param {Variable.types} [type] - Optionally, the value of the variable can be set to a type
*/
set: function (key, value, type) {
var variable = this.values.oneNormalizedVariable(this.prefix + key),
key = (this.prefix || '') + key;

var variable = this.values.oneNormalizedVariable(key),

// create an object that will be used as setter
update = { key: this.prefix + key, value: value };
update = { key, value };

_.isString(type) && (update.type = type);

Expand All @@ -262,11 +259,13 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ {
* @param {String} key -
*/
unset: function (key) {
key = (this.prefix || '') + key;

var lastDisabledVariable;

this.values.remove((variable) => {
// bail out if variable name didn't match
if (variable.key !== (this.prefix + key)) {
if (variable.key !== key) {
return false;
}

Expand All @@ -283,7 +282,7 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ {

// restore the reference with the last disabled variable
if (lastDisabledVariable) {
this.values.reference[this.prefix + key] = lastDisabledVariable;
this.values.reference[key] = lastDisabledVariable;
}

// track the change if mutation tracking is enabled
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,7 @@ declare module "postman-collection" {
* }
* @property [id] - ID of the scope
* @property [name] - A name of the scope
* @property [prefix] - A prefix to be used for variable names in this scope
* @property [values] - A list of variables defined in an array in form of `{name:String,
* value:String}`
*/
Expand Down

0 comments on commit e09a254

Please sign in to comment.