/** * Copyright JS Foundation and other contributors, http://js.foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ var util = require("@node-red/util").util; function Memory(config){ this.data = {}; } Memory.prototype.open = function(){ return Promise.resolve(); }; Memory.prototype.close = function(){ return Promise.resolve(); }; Memory.prototype._getOne = function(scope, key) { var value; var error; if(this.data[scope]){ try { value = util.getObjectProperty(this.data[scope], key); } catch(err) { if (err.code === "INVALID_EXPR") { throw err; } value = undefined; } } return value; } Memory.prototype.get = function(scope, key, callback) { var value; var error; if (!Array.isArray(key)) { try { value = this._getOne(scope,key); } catch(err) { if (!callback) { throw err; } error = err; } if (callback) { callback(error,value); return; } else { return value; } } value = []; for (var i=0; i