Example #1
0
		reversedChanges.forEach(function (change) {
			switch (change.type) {
				case 'add':
					objectPath.del(oldValue, change.path);
					break;
				case 'update':
					objectPath.set(oldValue, change.path, change.oldValue);
					break;
				case 'splice':
					var arr = objectPath.get(oldValue, change.path);
					if (!arr) {
						arr = [];
					}
					var args = change.removed;
					args.unshift(change.addedCount);
					args.unshift(change.index);
					Array.prototype.splice.apply(arr, args);
					objectPath.set(oldValue, change.path, arr);
					break;
				case 'delete':
					objectPath.set(oldValue, change.path, change.oldValue);
					break;
				default:
					objectPath.set(oldValue, change.path, change.oldValue);
			}
		});
Example #2
0
			data.changes.forEach(function (change) {
				switch (change.type) {
					case 'add':
					case 'update':
						objectPath.set(value, change.path, change.newValue);
						break;
					case 'splice':
						var arr = objectPath.get(value, change.path);
						var args = clone(change.added);
						args.unshift(change.removedCount);
						args.unshift(change.index);
						Array.prototype.splice.apply(arr, args);
						objectPath.set(value, change.path, arr);

						// Add a reference to the array being spliced.
						// This is required for other libs such as Polymer to make use of our change records.
						change.object = arr;
						break;
					case 'delete':
						objectPath.del(value, change.path);
						break;
					default:
						// Do nothing.
				}
			});
Example #3
0
    async.each(events, function(event, callback) {
        var oneEvent = mapper.event(event.id)
        var calEvent = {}
        if (!oneEvent['start-time']) { return callback() }
        var startDateTime = new Date(oneEvent['start-time'] + 'Z')
        if (startDateTime < minDate) { return callback() }
        // if (SDC.get(['relationships', oneEvent.id, 'parent'], []).indexOf(residenciesEid) !== -1) { return callback() }
        if (startDateTime > maxDate) { maxDate = startDateTime }

        calEvent.eid = op.get(oneEvent, ['performance', 'id'], op.get(oneEvent, ['id']))
        calEvent.tag = op.get(oneEvent, ['tag'], [])
        if (oneEvent.resident) {
          callback()
          return
          calEvent.controller = 'resident'
          calEvent.tag = ['event']
        }
        else if (op.get(oneEvent, ['performance', 'id'], false) !== false) {
          calEvent.controller = 'performance'
        }
        else {
          calEvent.controller = 'event'
        }
        // calEvent.controller = op.get(oneEvent, ['performance', 'id'], false) ? 'performance' : 'event'
        op.set(calEvent, ['name', 'et'], op.get(oneEvent, ['et-name']) === '' ? op.get(oneEvent, ['performance', 'artist']) : op.get(oneEvent, ['et-name']))
        op.set(calEvent, ['name', 'en'], op.get(oneEvent, ['en-name']) === '' ? op.get(oneEvent, ['performance', 'artist']) : op.get(oneEvent, ['en-name']))

        calEvent.time = ''
        if (oneEvent['start-time'].length >= 16) {
            calEvent.time = oneEvent['start-time'].slice(11,16).replace('00:00', '')
        }

        calEvent.location = {}
        calEvent.location.et = op.get(oneEvent, ['saal-location', 'et-name'], op.get(oneEvent, ['et-location'], 'Asukoht määramata!'))
        calEvent.location.en = op.get(oneEvent, ['saal-location', 'en-name'], op.get(oneEvent, ['en-location'], 'Location missing'))

        op.push(eventCalendar, [formatDate(oneEvent['start-time'].slice(0,10))], calEvent)
        if (oneEvent['end-time']) {
          var startD = new Date(oneEvent['start-time'] + 'Z')
          truncDate(startD)
          startD = new Date(startD.getTime() + 86400000)
          var endD = new Date(oneEvent['end-time'] + 'Z')
          truncDate(endD)
          calEventC = JSON.parse(JSON.stringify(calEvent))
          calEventC.time = ''
          while (endD >= startD) {
            op.push(eventCalendar, [formatDate(startD.toISOString().slice(0,10))], calEventC)
            startD = new Date(startD.getTime() + 86400000)
          }
        }

        callback()
    }, function(err) {
Example #4
0
 async.each(SDC.get(['local_entities', 'by_class', 'tour']), function(entity, callback) {
     var event = mapper.event(entity.id)
     // debug(JSON.stringify(event, null, 2))
     if (event['start-time']) {
         var eventDate = (event['start-time']).slice(0,10)
         if (eventDate < new Date().toJSON().slice(0,10)) { return callback(null) }
         var eventTime = (event['start-time']).slice(11,16)
         op.set(event, 'event-date', eventDate)
         op.set(event, 'event-time', eventTime)
         op.push(toursUpcoming, [eventDate, eventTime], event)
     }
     callback()
 }, function(err) {
Example #5
0
  differences.forEach((difference) => {
    let pathBase;
    let pathTip;
    if (difference.path) {
      pathBase = difference.path.length > 1 ? difference.path.slice(0, -1) : [];
      pathTip = difference.path[difference.path.length - 1];
    }

    switch (difference.kind) {
      case 'E':
        if (difference.path[0] === 'runners' && difference.rhs === '') {
          delete objectPath.get(run, pathBase)[pathTip];
        } else {
          objectPath.set(run, difference.path, difference.rhs);
        }

        delete objectPath.get(run.originalValues, pathBase)[pathTip];
        break;
      case 'N':
        if (typeof difference.rhs === 'object') {
          if (difference.path) {
            merge(objectPath.get(run, pathBase)[pathTip], difference.rhs);
          } else {
            merge(run, difference.rhs);
          }
        } else {
          objectPath.set(run, difference.path, difference.rhs);
        }

        break;
      case 'D':
        if (difference.path) {
          delete objectPath.get(run.originalValues, pathBase)[pathTip];
        } else {
          for (const key in difference.lhs) {
            /* istanbul ignore if */
            if (!{}.hasOwnProperty.call(difference.lhs, key)) {
              continue;
            }

            delete run.originalValues[key];
          }
        }
        break;
      /* istanbul ignore next: shouldn't be possible */
      default:
        throw new Error(
          `Unexpected difference:\n${JSON.stringify(difference)}`);
    }
  });
Example #6
0
 async.each(SDC.get(['local_entities', 'by_class', 'program']), function(entity, callback) {
     var event = mapper.event(entity.id)
     if (event['start-time']) {
         if (new Date() > new Date(event['start-time'])) {
             return callback()
         }
         // debug(new Date().toJSON(), event['start-time'], new Date(event['start-time']).toJSON())
         var eventDate = (event['start-time']).slice(0,10)
         var eventTime = (event['start-time']).slice(11,16)
         op.set(event, 'event-date', eventDate)
         op.set(event, 'event-time', eventTime)
         op.push(programUpcoming, [eventDate, eventTime], event)
     }
     callback()
 }, function(err) {
Example #7
0
  mergeEnv(prefix) {
    // try environment variables
    for (const envKey in process.env) {
      let key = envKey.toLowerCase();

      // only accept keys prefixed with the prefix
      if (key.indexOf(prefix.toLowerCase()) < 0) {
        continue;
      }

      const val = BaseRegistry.normalizeConfigOption(process.env[envKey]);

      // remove config prefix
      key = (0, (_misc || _load_misc()).removePrefix)(key, prefix.toLowerCase());

      // replace dunders with dots
      key = key.replace(/__/g, '.');

      // replace underscores with dashes
      key = key.replace(/_/g, '-');

      // set it via a path
      objectPath.set(this.config, key, val);
    }
  }
Example #8
0
			_.each(update.$rename, (value, field) => {
				let curValue = objectPath.get(record, field);
				if (curValue !== undefined) {
					objectPath.set(record, value, curValue);
					objectPath.del(record, field);
				}
			});
Example #9
0
			fields.forEach((field) => {
				if (field.indexOf('.') !== -1) {
					objectPath.set(picked, field, objectPath.get(obj, field));
				} else {
					picked[field] = obj[field];
				}
			});
Example #10
0
			_.each(update.$pullAll, (value, field) => {
				let curValue = objectPath.get(record, field);
				if (Array.isArray(curValue)) {
					curValue = _.difference(curValue, value);
					objectPath.set(record, field, curValue);
				}
			});
Example #11
0
	updateDiffById(id, diff) {
		// TODO remove - ignore updates in room.usernames
		if (this.collectionName === 'rocketchat_room' && diff.usernames) {
			delete diff.usernames;
		}

		const record = this._findByIndex('_id', id);
		if (!record) {
			console.error('Cache.updateDiffById: No record', this.collectionName, id, diff);
			return;
		}

		const updatedFields = _.without(Object.keys(diff), ...this.ignoreUpdatedFields);

		if (updatedFields.length > 0) {
			this.emit('beforeupdate', record, diff);
		}

		for (let key in diff) {
			if (diff.hasOwnProperty(key)) {
				objectPath.set(record, key, diff[key]);
			}
		}

		this.collection.update(record);

		if (updatedFields.length > 0) {
			this.emit('updated', record, diff);
		}
	}
Example #12
0
    Object.getOwnPropertyNames(convert).forEach(function(prop) {
      var type = convert[prop];
      var val = objectPath.get(data, prop);
      var newVal = val;

      switch (type) {
        case 'date':
          if (val < 10000000000) {
            val *= 1000;
          }
          newVal = (new Date(val)).toISOString();
          break;

        case 'number':
          newVal = Number(val);
          break;

        case 'string':
          newVal = String(val);
          break;

        default:
          throw(new Error('No type conversion for \'' + type + '\''));
          break;
      }
      objectPath.set(data, prop, newVal);
    })
Example #13
0
	dependencies.forEach(dependency_id => {
		const result = auto_results[dependency_id];
		const module = result.module;

		const path = `${module.type}s.${module.namespace_id}/${module.sub_id}`;
		//console.log('inserting ' + path);
		set(results, path, result.data);
	});
 _dependentKey.split(".").forEach(function (subKey) {
   subPath = subPath === "" ? subKey : subPath + "." + subKey;
   var nodesSubPath = subPath + "." + nodesField;
   if (!o.has(dependentKeysTree, nodesSubPath)) {
     o.set(dependentKeysTree, nodesSubPath, _getNodesField());
   }
   o.insert(dependentKeysTree, nodesSubPath, node);
 });
Example #15
0
 async.each(SDC.get(['local_entities', 'by_class', 'residency']), function(entity, callback) {
     var event = mapper.event(entity.id)
     // console.log(JSON.stringify(event, null, 2))
     if (event['end-time']) {
         var eventEndDate = (event['end-time']).slice(0,10)
         if (eventEndDate < new Date().toJSON().slice(0,10)) { return callback(null) }
     }
     else { return callback(null) }
     if (event['start-time']) {
         var eventDate = (event['start-time']).slice(0,10)
         var eventTime = (event['start-time']).slice(11,16)
         op.set(event, 'event-date', eventDate)
         op.set(event, 'event-time', eventTime)
         op.push(residencyPast, [eventDate, eventTime], event)
     }
     callback()
 }, function(err) {
Example #16
0
REXStat.prototype.inc = function(path, inc, suffix) {
	if (!inc) { inc = 1; }
	var tpath = suffix ? path + ".total" : path,
		spath = path + suffix;
	objpath.set(
		this.stat,
		tpath,
		zint(objpath.get(this.stat, path + ".total", 0)) + inc
	);
	if (suffix) {
		objpath.set(
			this.stat,
			path + suffix,
			zint(objpath.get(this.stat, path + suffix, 0)) + inc
		);
	}
}
Example #17
0
    async.each(SDC.get(['local_entities', 'by_class', 'program']), function(entity, callback) {
        var event = mapper.event(entity.id)
        // console.log(JSON.stringify(event, null, 2))
        if (!event['start-time']) { return callback() }

        if (new Date(event['start-time']) > maxDate) { maxDate = new Date(event['start-time']) }

        var performanceEid = op.get(event, ['performance', 'id'])
        var perfCatIds = SDC.get(['relationships', performanceEid, 'category'], []).map(function(eId) { return parseInt(eId, 10) })
        // debug('a', perfCatIds, pr_categories)
        perfCatIds.sort(function(a,b) { return a-b })

        var intersects = false
        var ai = 0, bi = 0
        while( ai < perfCatIds.length && bi < categories.length && !intersects )
        {
            if      (perfCatIds[ai] < categories[bi]) { ai = ai + 1 }
            else if (perfCatIds[ai] > categories[bi]) { bi = bi + 1 }
            else { intersects = true }
        }

        if (month - 1 !== new Date(event['start-time']).getUTCMonth()) {
            // console.log(month - 1, '!==', new Date(event['start-time']).getUTCMonth())
            return callback()
        }
        if (parseInt(year, 10) !== new Date(event['start-time']).getUTCFullYear()) {
            // console.log(year, '!==', new Date(event['start-time']).getUTCFullYear())
            return callback()
        }

        if (intersects) {
            // console.log(event.id + '[performance_eid]', categories, ' intersects ', JSON.stringify(perfCatIds))
        } else {
            // console.log(event.id + '[performance_eid]', categories, ' doesnot intersect ', JSON.stringify(perfCatIds))
            return callback()
        }

        var eventDate = (event['start-time']).slice(0,10)
        var eventTime = (event['start-time']).slice(11,16)
        op.set(event, 'event-date', eventDate)
        op.set(event, 'event-time', eventTime)
        op.push(programA, [eventDate, eventTime], event)

        callback()
    }, function(err) {
Example #18
0
module.exports = function (active) {
  var output = {};

  if (active < 1) return output;

  objectPath.set(output, 'lineBreak.before.EndOfFile', 1);

  return output;
};
Example #19
0
  objectPathSet: function (obj, path, value) {
    var [initialKey] = path.split(".");

    if (obj[initialKey] == null) {
      obj[initialKey] = {};
    }

    objectPath.set(obj, path, value);
  },
Example #20
0
 core.computer.run(function(err) {
   if (err instanceof Error) {
     console.error(kuler("Unable to compute some fields.", "red"), kuler(err.toString(), 'orangered'));
   }
   else {
     console.info(kuler('Corpus fields computed.', 'olive'));
     objectPath.set(core.states, 'hotfolder.first.syncOver', true);
   }
 });
Example #21
0
			_.each(update.$mul, (value, field) => {
				let curValue = objectPath.get(record, field);
				if (curValue === undefined) {
					curValue = 0;
				} else {
					curValue *= value;
				}
				objectPath.set(record, field, curValue);
			});
Example #22
0
 function addEvent (entityId, path, eventType, fn) {
   keypath.set(handlers, [entityId, path, eventType], throttle(function (e) {
     var entity = entities[entityId]
     if (entity) {
       fn.call(null, e, entity.context, setState(entity))
     } else {
       fn.call(null, e)
     }
   }))
 }
Example #23
0
function translate(key) {
    var value = op.get(i18nConfig, 'translations.' + key + '.' + i18nConfig.lang)
    if (!value && i18nConfig.updateFile === true && i18nConfig.locales.indexOf(i18nConfig.lang) > -1) {
        op.set(i18nConfig, 'translations.' + key + '.' + i18nConfig.lang, key)

        fs.writeFile(i18nConfig.file, yaml.safeDump(i18nConfig.translations, { sortKeys: true, indent: 4 }), function(err) {
            if (err) { return console.log(err) }
        })
    }
    return value || key
}
Example #24
0
			_.each(update.$pop, (value, field) => {
				let curValue = objectPath.get(record, field);
				if (Array.isArray(curValue)) {
					if (value === -1) {
						curValue.shift();
					} else {
						curValue.pop();
					}
					objectPath.set(record, field, curValue);
				}
			});
Example #25
0
function IndexManager(mainDb, properties) {
  if (!(this instanceof IndexManager))
    return new IndexManager(mainDb, properties);

  this.mainDb = mainDb;
  this.properties = properties;
  this.indexName = indexName(properties);
  this.indexDb = mainDb.sublevel(this.indexName);
  objectPath.set(this.indexDb, "indico._indexManager", this);
  this.registerHooks();
}
Example #26
0
  _handleUpdate: function(path, value) {
    if (this.props.onUpdate) {
      this.props.onUpdate.call(this, path, value);
      return;
    }

    //TODO(korbin): Write immutable objectPath library.
    var object = React.__spread({}, this.state.object);
    objectPath.set(object, path.toArray(), value);
    this.setState({object: object});
  }
BrowserSync.prototype.setOption = function (name, value) {

    var objectPath = require("object-path");

    if (!_.isUndefined(objectPath.get(this.options, name))) {
        this.debug("Setting option: {magenta:%s", name);
        objectPath.set(this.options, name, value);
        this.events.emit("options:set", {name: name, value: value, options: this.options});
    }

    return this.options;
};
Example #28
0
 .then((target) => {
   if (!target) {
     throw new Error('Invalid reference');
   }
   this[options.path || options] = target;
   fillPath = fillPath.concat(options.path || options);
   objectPath.set(returnObj, fillPath, target);
   if (options.populate) {
     return this[options.path || options].populate(options.populate, returnObj, fillPath);
   }
   return returnObj;
 });
Example #29
0
module.exports = function(mainDb, properties, doNotCreate) {
  var idxName = indexName(properties);
  //check the index managers already registered into the mainDb
  if(!objectPath.get(mainDb, "indico._indexManagers."+idxName)) {
    if(doNotCreate) {
      throw new Error("Index not defined for properties: " + properties);
    }

    objectPath.set(mainDb, "indico._indexManagers."+idxName, new IndexManager(mainDb, properties));
  }
  return mainDb.indico._indexManagers[idxName];
};
Example #30
0
  fs.readFile(file, 'utf-8', function(err, data) {
    if(err) {
      return callback(err);
    }

    var obj = {};
    if(data) {
      obj = JSON.parse(data);
    }

    objectPath.set(obj, key, val);
    fs.writeFile(file, JSON.stringify(obj, null, "  "), callback);
  });