Skip to content

Commit

Permalink
feat: support prefix in VariableScope
Browse files Browse the repository at this point in the history
This change allows us to use the current VariableScope
with VaultVariables which have a fixed 'vault' prefix
  • Loading branch information
Pranav Joglekar committed Jul 15, 2024
1 parent e1dfe7a commit 7c67eb9
Show file tree
Hide file tree
Showing 3 changed files with 1,552 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/collection/variable-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ _.inherit((
if (mutations) {
this.mutations = new MutationTracker(mutations);
}

if (definition && definition.prefix) {
this.prefix = definition.prefix;
}
}), Property);

/**
Expand All @@ -136,6 +140,16 @@ _.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 @@ -176,7 +190,7 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ {
* false otherwise
*/
has: function (key) {
var variable = this.values.oneNormalizedVariable(key),
var variable = this.values.oneNormalizedVariable(this.prefix + key),
i,
ii;

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

Expand All @@ -222,10 +236,10 @@ _.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(key),
var variable = this.values.oneNormalizedVariable(this.prefix + key),

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

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

Expand All @@ -250,9 +264,9 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ {
unset: function (key) {
var lastDisabledVariable;

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

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

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

// track the change if mutation tracking is enabled
Expand Down
Loading

0 comments on commit 7c67eb9

Please sign in to comment.