out += ' title=\"' + title + '\"';
  }
  return (out + '>' + text + '</a>');
};

const markedOptions = {
  sanitize: true,
  breaks: true,
  highlight: function (code) {
    return hljs.highlightAuto(code).value;
  },
  renderer: mdRenderer
};


const inversedEmojiCharacters = _.invert(_.mapValues(emojiCharacters, (e) => e.character));

const emojiVariants = _.map(Object.keys(inversedEmojiCharacters), function(name) {
  return name.replace(/\+/g, '\\+');
});

const emojiRegexp = new RegExp('(' + emojiVariants.join('|') + ')', 'gi');

const processText = function(text) {
  let markedText = marked(text, markedOptions);

  // need hack with replace because of https://github.com/Ranks/emojify.js/issues/127
  const noPTag = markedText.replace(/<p>/g, '<p> ');

  let emojifiedText = emojify
    .replace(noPTag.replace(emojiRegexp, (match) => ':' + inversedEmojiCharacters[match] + ':'));
Example #2
0
const parseObjectKeyValueToMongoObjectKeyValue = (className, restKey, restValue, schema) => {
  // Check if the schema is known since it's a built-in field.
  let transformedValue;
  let coercedToDate;
  switch(restKey) {
  case 'objectId': return {key: '_id', value: restValue};
  case 'createdAt':
    transformedValue = transformTopLevelAtom(restValue);
    coercedToDate = typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue
    return {key: '_created_at', value: coercedToDate};
  case 'updatedAt':
    transformedValue = transformTopLevelAtom(restValue);
    coercedToDate = typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue
    return {key: '_updated_at', value: coercedToDate};
  case 'expiresAt':
    transformedValue = transformTopLevelAtom(restValue);
    coercedToDate = typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue
    return {key: 'expiresAt', value: coercedToDate};
  case '_rperm':
  case '_wperm':
  case '_email_verify_token':
  case '_hashed_password':
  case '_perishable_token': return {key: restKey, value: restValue};
  case 'sessionToken': return {key: '_session_token', value: restValue};
  default:
    // Auth data should have been transformed already
    if (restKey.match(/^authData\.([a-zA-Z0-9_]+)\.id$/)) {
      throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'can only query on ' + restKey);
    }
    // Trust that the auth data has been transformed and save it directly
    if (restKey.match(/^_auth_data_[a-zA-Z0-9_]+$/)) {
      return {key: restKey, value: restValue};
    }
  }
  //skip straight to transformTopLevelAtom for Bytes, they don't show up in the schema for some reason
  if (restValue && restValue.__type !== 'Bytes') {
    //Note: We may not know the type of a field here, as the user could be saving (null) to a field
    //That never existed before, meaning we can't infer the type.
    if (schema.fields[restKey] && schema.fields[restKey].type == 'Pointer' || restValue.__type == 'Pointer') {
      restKey = '_p_' + restKey;
    }
  }

  // Handle atomic values
  var value = transformTopLevelAtom(restValue);
  if (value !== CannotTransform) {
    return {key: restKey, value: value};
  }

  // ACLs are handled before this method is called
  // If an ACL key still exists here, something is wrong.
  if (restKey === 'ACL') {
    throw 'There was a problem transforming an ACL.';
  }

  // Handle arrays
  if (restValue instanceof Array) {
    value = restValue.map(transformInteriorValue);
    return {key: restKey, value: value};
  }

  // Handle update operators. TODO: handle within Parse Server. DB adapter shouldn't see update operators in creates.
  if (typeof restValue === 'object' && '__op' in restValue) {
    return {key: restKey, value: transformUpdateOperator(restValue, true)};
  }

  // Handle normal objects by recursing
  if (Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
    throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
  }
  value = _.mapValues(restValue, transformInteriorValue);
  return {key: restKey, value};
}
        var migrateV4 = function (project) {
            let manifest = project.manifest;
            let paths = project.paths;

            if (manifest.package_version <= 4) {
                let dir = project.paths.projectDir;
                // translation type
                let typeId = _.get(manifest, 'project.type', 'text').toLowerCase();
                let typeNames = {
                    text: 'Text',
                    tn: 'Notes',
                    tq: 'Questions',
                    tw: 'Words',
                    ta: 'Academy'
                };
                if(_.has(manifest, 'project.type')) {
                    delete manifest.project.type;
                }
                manifest.type = {
                    id: typeId,
                    name: _.get(typeNames, typeId, '')
                };

                // update project
                // NOTE: this was actually in v3 but we missed it so we need to catch it here
                if(_.has(manifest, 'project_id')) {
                    manifest.project = {
                        id: manifest.project_id,
                        name: ""
                    };
                    delete manifest.project_id;
                }

                // update resource
                let resourceNames = {
                    ulb: 'Unlocked Literal Bible',
                    udb: 'Unlocked Dynamic Bible',
                    obs: 'Open Bible Stories',
                    reg: 'Regular'
                };
                if(_.has(manifest, 'resource_id')) {
                    let resourceId =_.get(manifest, 'resource_id', 'reg');
                    delete manifest.resource_id;
                    manifest.resource = {
                        id: resourceId,
                        name: _.get(resourceNames, resourceId, '')
                    };
                } else if(!_.has(manifest, 'resource')) {
                    // add missing resource
                    if(_.get(manifest, 'type.id') === 'text') {
                        let resourceId =_.get(manifest, 'project.id') === 'obs' ? 'obs' : 'reg';
                        manifest.resource = {
                            id: resourceId,
                            name: _.get(resourceNames, resourceId, '')
                        };
                    }
                }

                // update source translations
                manifest.source_translations = _.values(_.mapValues(manifest.source_translations, function(value, key) {
                    let parts = key.split('-');
                    if(parts.length > 2) {
                        let languageResourceId = key.substring(parts[0].length + 1, key.length);
                        let pieces = languageResourceId.split('-');
                        if(pieces.length > 0) {
                            let resourceId = pieces[pieces.length - 1];
                            value.resource_id = resourceId;
                            value.language_id = languageResourceId.substring(0, languageResourceId.length - resourceId.length - 1);
                        }
                    }
                    return value;
                }));

                // update parent draft
                if(_.has(manifest, 'parent_draft_resource_id')) {
                    manifest.parent_draft = {
                        resource_id: manifest.parent_draft_resource_id,
                        checking_entity: '',
                        checking_level: '',
                        comments: 'The parent draft is unknown',
                        contributors: '',
                        publish_date: '',
                        source_text: '',
                        source_text_version: '',
                        version: ''
                    };
                    delete manifest.parent_draft_resource_id;
                }

                // update finished chunks
                manifest.finished_chunks = _.get(manifest, 'finished_frames', []);
                delete manifest.finished_frames;

                // remove finished titles
                _.forEach(_.get(manifest, 'finished_titles'), function(value, index) {
                    let finishedChunks = _.get(manifest, 'finished_chunks', []);
                    finishedChunks.push(value + '-title');
                    manifest.finished_chunks = _.unique(finishedChunks);
                });
                delete manifest.finished_titles;

                // remove finished references
                _.forEach(_.get(manifest, 'finished_references'), function(value, index) {
                    let finishedChunks = _.get(manifest, 'finished_chunks', []);
                    finishedChunks.push(value + '-reference');
                    manifest.finished_chunks = _.unique(finishedChunks);
                });
                delete manifest.finished_references;

                // remove project components
                _.forEach(_.get(manifest, 'finished_project_components'), function(value, index) {
                    let finishedChunks = _.get(manifest, 'finished_chunks', []);
                    finishedChunks.push('00-'+value);
                    manifest.finished_chunks = _.unique(finishedChunks);
                });
                delete manifest.finished_project_components;

                // add format
                if(!_.has(manifest, 'format') || manifest.format === 'usx' || manifest.format === 'default') {
                    manifest.format = _.get(manifest, 'type.id', 'text') !== 'text' || _.get(manifest, 'project.id') === 'obs' ? 'markdown' : 'usfm';
                }

                // update package version
                manifest.package_version = 5;

                // update where project title is saved
                let oldProjectTitlePath = path.join(dir, 'title.txt');
                let projectTranslationDir = path.join(dir, '00');
                let newProjectTitlePath = path.join(projectTranslationDir, 'title.txt');
                if(fs.existsSync(oldProjectTitlePath)) {
                    try {
                        fs.mkdirSync(projectTranslationDir);
                    } catch (e) {
                        console.log(e);
                    }
                    let projectTitle = fs.readFileSync(oldProjectTitlePath).toString();
                    fs.writeFileSync(newProjectTitlePath, projectTitle);
                    fs.unlinkSync(oldProjectTitlePath);
                }
            }

            return {manifest: manifest, paths: paths};
        };
Example #4
0
            return new Promise(function (resolve, reject) {
                if (meta.project_type_class === "standard") {
                    // normalize input
                    var chapters = _.mapValues(_.groupBy(translation, function (obj) {
                        //console.debug('map chapter values', obj);
                        return obj.chunkmeta.chapterid;
                    }), function (chapter, key) {
                        var frames = _.mapKeys(chapter, function (obj) {
                            //console.debug('map chapter keys', obj);
                            return obj.chunkmeta.frameid;
                        });

                        var chapterObj = {
                            id: key,
                            title: frames.title || key,
                            reference: frames.reference === undefined ? null : frames.reference,
                            format: meta.format
                        };
                        delete frames.reference;
                        delete frames.title;
                        chapterObj.frames = _.sortBy(_.filter(frames, function (o) {
                            return o.transcontent !== '';
                        }), function (f) {
                            //console.debug('sort frames',f);
                            return f.chunkmeta.frame;
                        });
                        return chapterObj;
                    });
                    var project = {
                        format: meta.format,
                        title: chapters['00'].title
                    };
                    delete chapters['00'];
                    project.chapters = _.sortBy(_.filter(chapters, function (o) {
                        return o.frames.length > 0;
                    }), 'id');
                    chapters = null;

                    if (project.format === 'markdown') {

                        var doc = new PDFDocument({
                            bufferPages: true,
                            margins:{
                                top: 72,
                                bottom: 50,
                                left: 72,
                                right: 72
                            }
                        });
                        doc.pipe(fs.createWriteStream(filePath));
                        // default meta
                        if (project.title.transcontent !== "") {
                            doc.info.Title = project.title.transcontent;
                        } else {
                            doc.info.Title = project.title.projectmeta.project.name;
                        }

                        //doc.info.Author = 'Joel Lonbeck'; // todo: translators
                        //doc.info.Subject = 'an unrestricted, visual mini-Bible in any language'; // todo: project sub-title
                        doc.info.Keywords = meta.target_language.name;

                        // book title
                        doc.fontSize(25)
                            .font(targetfont)
                            .text(doc.info.Title, 72, doc.page.height / 2, {align: 'center'});

                        mythis.renderLicense(doc, "OBS_LICENSE.md");

                        // TOC placeholders
                        doc.addPage();
                        var lastTOCPage = doc.bufferedPageRange().count;
                        var tocPages = {
                            start: lastTOCPage - 1
                        };
                        doc.fontSize(25)
                            .text(' ', 72, 72)
                            .moveDown();
                        _.forEach(project.chapters, function (chapter) {
                            doc.fontSize(10)
                                .text(' ')
                                .moveDown();
                            var currPage = doc.bufferedPageRange().count;
                            if (lastTOCPage !== currPage) {
                                // record toc page split
                                tocPages[chapter.id] = currPage - 1;
                                lastTOCPage = currPage;

                                // give room for header on new page
                                doc.fontSize(25)
                                    .text(' ', 72, 72)
                                    .moveDown();
                            }
                        });

                        // book body
                        _.forEach(project.chapters, function (chapter) {
                            // chapter title
                            doc.addPage();
                            doc.fontSize(20)
                                .text(chapter.title.transcontent || chapter.title.chunkmeta.title, 72, doc.page.height / 2, {align: 'center'});
                            chapter.page = doc.bufferedPageRange().count;

                            // frames
                            if (options.doubleSpace === true) {
                                doc.lineGap(20);
                            }
                            doc.addPage();
                            _.forEach(chapter.frames, function (frame) {
                                if (options.includeIncompleteFrames === true || frame.completed === true) {
                                    doc.moveDown();
                                    if (options.includeImages === true) {
                                        //console.debug(meta);
                                        //console.debug(frame);
                                        // TRICKY: right now all images are en
                                        var imgPath = path.join(imagePath, meta.resource.id + "-en-" + frame.chunkmeta.chapterid + "-" + frame.chunkmeta.frameid + ".jpg");
                                        //check the position of the text on the page.
                                        // 792 (total ht of page) - 50 ( lower margin) - 263.25 (height of pic) = 478.75 (max amount of space used before image)
                                        if (doc.y > 478.75) {
                                            doc.addPage();
                                        }
                                       doc.image(imgPath, {width:doc.page.width - 72*2});
                                    }
                                    doc.fontSize(10)
                                        .text(frame.transcontent);
                                    if (options.includeImages === true) {
                                        doc.moveDown();//add extra line break after image and text as per github issue527
                                    }
                                }
                            });

                            // chapter reference
                            if (chapter.reference !== null) {
                                doc.moveDown()
                                    .fontSize(10)
                                    .text(chapter.reference.transcontent);
                            }
                        });

                        // number pages
                        var range = doc.bufferedPageRange();
                        for (var i = range.start; i < range.start + range.count; i ++) {
                            doc.switchToPage(i);
                            doc.fontSize(10)
                                .font(defaultfont)
                                .text(i + 1, 72, doc.page.height - 50 - 12, {align: 'center'});
                        }

                        // write TOC
                        var currTocPage = tocPages.start;
                        doc.switchToPage(currTocPage);
                        // TODO: display correct title of TOC based on the project
                        doc.fontSize(25)
                            .lineGap(0)
                            .text('Table of Contents', 72, 72)
                            .font(targetfont)
                            .moveDown();
                        _.forEach(project.chapters, function (chapter) {
                            if (tocPages[chapter.id] !== undefined && tocPages[chapter.id] !== currTocPage) {
                                currTocPage = tocPages[chapter.id];
                                doc.switchToPage(currTocPage);
                                doc.fontSize(10)
                                    .text(' ')
                                    .moveUp();
                            }
                            doc.switchToPage(currTocPage);
                            doc.fontSize(10)
                                .text(chapter.title.transcontent || chapter.title.chunkmeta.title)
                                .moveUp()
                                .text(chapter.page + '', {align: 'right'})
                                .moveDown();
                        });

                        doc.end();
                        resolve(true);
                    } else if (project.format === 'usfm') {

                         var doc = new PDFDocument({
                            bufferPages: true,
                            margins:{
                                top: 72,
                                bottom: 50,
                                left: 72,
                                right: 72
                            }
                        });
                        doc.pipe(fs.createWriteStream(filePath));

                        //set the title
                        doc.info.Title = translation[0].transcontent || meta.project.name;
                        doc.fontSize(25)
                            .font(targetfont)
                            .text(doc.info.Title, 72, doc.page.height / 2, {align: 'center'});

                        mythis.renderLicense(doc, "LICENSE.md");

                             // book body
                        _.forEach(project.chapters, function (chapter) {

                            doc.addPage();//start each chapter on new page

                            //list chapters (remove leading zeros in the numbers)
                            var chapterNum = chapter.id.replace(/\b0+/, '');
                            doc.fontSize(20)
                                .lineGap(10)
                                .text(chapterNum + ' ', {continued: true});
                            chapter.page = doc.bufferedPageRange().count;

                            // frames
                            if (options.doubleSpace === true) {
                                doc.lineGap(20);
                            }

                            _.forEach(chapter.frames, function (frame) {
                                if (options.includeIncompleteFrames === true || frame.completed === true) {
                                    var content = frame.transcontent.split(/[\\]*[\\||\/][v][ ]([0-9]+)/g);

                                    _.forEach(content, function (info) {
                                        let output = info;
                                       //superscript for verses not supported by pdfkit: https://github.com/devongovett/pdfkit/issues/15
                                       output = output.replace(/[\\][\\c][ ][0-9]+ /g, '');
                                        doc.fontSize(10)
                                            .text(output + ' ',  { continued: true});
                                    });
                                }
                                doc.moveDown()
                                    .text("");
                            });
                        });

                        // number pages
                        var range = doc.bufferedPageRange();
                        for (var i = range.start; i < range.start + range.count; i ++) {
                            doc.switchToPage(i);
                            doc.fontSize(10)
                                .font(defaultfont)
                                .text(i + 1, 72, doc.page.height - 50 - 12, {align: 'center'});
                        }

                        doc.end();
                        resolve(true);
                    } else {
                        reject('We only support printing OBS and Bible projects for now');
                    }
                } else {
                    // TODO: support exporting other target translation types if needed e.g. notes, words, questions
                    reject('We do not support printing that project type yet');
                }
            });
Example #5
0
 loadCommand(pluginName, details, key) {
   const commands = _.mapValues(details.commands, (subDetails, subKey) =>
     this.loadCommand(pluginName, subDetails, `${key}:${subKey}`)
   );
   return _.assign({}, details, { key, pluginName, commands });
 }
Example #6
0
const amendOptions = options => {
  return _.mapValues(options, amendOption)
}
function addStats(stats1, stats2) {
    return _.mapValues(stats1, function (value, key) {
        return value + stats2[key];
    });
}
const struct = structJs();

const isBrowser = typeof window !== 'undefined';
// eslint-disable-next-line no-console
const debug = isBrowser ? require('bows')('FreeStyleLibreDriver') : console.log;

const FORMAT = {
  ERROR: 'bb',
  DATE_TIME: 'bbbbbsb',
  RECORD_HEADER: 'sbbin',
  HISTORICAL_DATA: 'ssss',
  TIME_CHANGE: 'insss', // despite the specs, user time offset is a signed value, same as in header
  USER_TIME_CHANGE: 'nssss',
};

export const FORMAT_LENGTH = _.mapValues(FORMAT, format => struct.structlen(format));

const OP_CODE_PROCESSING_ORDER = [
  OP_CODE.GET_CFG_SCHEMA, // not used for now
  OP_CODE.GET_DB_SCHEMA, // not used for now
  OP_CODE.GET_DATE_TIME,
  OP_CODE.GET_CFG_DATA,
  OP_CODE.COMPRESSED_DATABASE,
  OP_CODE.GET_DATABASE,
];

export default class FreeStyleLibreData {
  constructor(cfg) {
    this.cfg = cfg;

    this.opCodeHandlers = {};
var processEvent = cocb.wrap(function*(core, ctx){
    ctx.emit("debug", "event being processed");

    //the schedule is the list of rules and events that need to be processed
    var schedule = [];
    var responses = [];//i.e. directives

    var addEventToSchedule = function(ctx, callback){
        selectRulesToEval(core, ctx, function(err, rules){
            if(err) return callback(err);
            _.each(rules, function(rule){
                ctx.emit("debug", "rule added to schedule: " + rule.rid + " -> " + rule.name);
                schedule.push({
                    rule: rule,
                    event: ctx.event,
                    pico_id: ctx.pico_id,
                });
            });
            if(schedule.length === 0){
                ctx.emit("debug", "no rules added to schedule");
            }
            callback();
        });
    };

    yield cocb.toYieldable(addEventToSchedule)(ctx);

    //these are special functions only to be used inside a rule body
    var rule_body_fns = {
        raiseEvent: cocb.toYieldable(function(revent, callback){
            //shape the revent like a normal event
            var event = {
                eci: ctx.event.eci,//raise event is always to the same pico
                eid: ctx.event.eid,//inherit from parent event to aid in debugging
                domain: revent.domain,
                type: revent.type,
                attrs: revent.attributes,
                for_rid: revent.for_rid,
                txn_id: ctx.event.txn_id,//inherit from parent event
                timestamp: new Date()
            };
            //must make a new ctx for this raise b/c it's a different event
            var raise_ctx = core.mkCTX({
                event: event,
                pico_id: ctx.pico_id,//raise event is always to the same pico
            });
            raise_ctx.emit("debug", "adding raised event to schedule: " + revent.domain + "/" + revent.type);
            addEventToSchedule(raise_ctx, callback);
        }),
        raiseError: function*(ctx, level, data){

            if(level === "error"){
                //clear the schedule so no more rules are run
                schedule = [];
            }

            return yield ctx.raiseEvent({
                domain: "system",
                type: "error",
                attributes: {
                    level: level,
                    data: data,
                    rid: ctx.rid,
                    rule_name: ctx.rule_name,
                    genus: "user",
                    //species: ??,
                },
                for_rid: ctx.rid,
            });
        },
        scheduleEvent: cocb.toYieldable(function(sevent, callback){
            scheduleEvent(core, ctx, {
                domain: sevent.domain,
                type: sevent.type,
                attributes: sevent.attributes,

                at: sevent.at,
                timespec: sevent.timespec,
            }, callback);
        }),
        addActionResponse: function(ctx, type, val){
            var resp = toResponse(ctx, type, val);
            responses.push(resp);
            return resp;
        },
        stopRulesetExecution: function(){
            ctx.emit("debug", "`last` control statement is stopping ruleset execution");
            schedule = [];
        },
    };

    //using a while loop b/c schedule is MUTABLE
    //Durring execution new events may be `raised` that will mutate the schedule
    while(schedule.length > 0){
        yield runRuleBody(core, rule_body_fns, schedule.shift());
    }

    var res_by_type = _.groupBy(responses, "type");

    var r = _.mapValues(res_by_type, function(responses, key){
        if(key === "directive"){
            return _.map(responses, function(d){
                return _.omit(d, "type");
            });
        }
        return responses;
    });

    //handle event:send() actions
    if(_.has(r, "event:send")){
        _.each(r["event:send"], function(o){
            core.signalEvent(o.event);
        });
        delete r["event:send"];
    }


    if(_.has(r, "directive")){
        r.directives = r.directive;
        delete r.directive;
    }else{
        //we always want to return a directives array even if it's empty
        r.directives = [];
    }

    ctx.emit("debug", "event finished processing");

    return r;
});
Example #10
0
 return partialFiles(name, partialDirs).then(function (partialFiles) {
     return deep(_.mapValues(partialFiles, function (file) {
         debug("reading ",file);
         return qfs.read(file);
     }));
 });
 data = _.map(data, d => _.mapValues(d, parseInt));
Example #12
0
      function done(err) {
        if (err) {
          debug(err);
          let errCode = err.code || err.message;
          // FIXME: Should not need to have to emit manually here
          ee.emit('error', errCode);
          return callback(err, context);
        }

        // Assemble the new request params
        if (params.json) {
          requestParams.json = template(params.json, context);
        }

        if (params.body) {
          requestParams.body = template(params.body, context);
        }

        if (params.form) {
          requestParams.form = _.reduce(
            requestParams.form,
            function (acc, v, k) {
              acc[k] = template(v, context);
              return acc;
            },
            {});
        }

        // Assign default headers then overwrite as needed
        let defaultHeaders = lowcaseKeys(
          (config.defaults && config.defaults.headers) ?
            config.defaults.headers : {'user-agent': USER_AGENT});
        const combinedHeaders = _.extend(defaultHeaders, lowcaseKeys(params.headers), lowcaseKeys(requestParams.headers));
        const templatedHeaders = _.mapValues(combinedHeaders, function(v, k, obj) {
          return template(v, context);
        });
        requestParams.headers = templatedHeaders;

        let defaultCookie = config.defaults ? config.defaults.cookie || {} : {};

        let cookie = _.reduce(
          params.cookie,
          function(acc, v, k) {
            acc[k] = v;
            return acc;
          },
          defaultCookie);

        if (cookie) {
          _.each(cookie, function(v, k) {
            context._jar.setCookie(k + '=' + template(v, context), requestParams.url);
          });
        }

        if (typeof requestParams.auth === 'object') {
          requestParams.auth.user = template(requestParams.auth.user, context);
          requestParams.auth.pass = template(requestParams.auth.pass, context);
        }

        let url = maybePrependBase(template(requestParams.uri || requestParams.url, context), config);

        if (requestParams.uri) {
          // If a hook function sets requestParams.uri to something, request.js
          // will pick that over .url, so we need to delete it.
          delete requestParams.uri;
        }

        requestParams.url = url;

        if (!self.pool) {
          if ((/^https/i).test(requestParams.url)) {
            requestParams.agent = context._httpsAgent;
          } else {
            requestParams.agent = context._httpAgent;
          }
        } else {
          requestParams.pool = self.pool;
        }

        function requestCallback(err, res, body) {
          if (err) {
            return;
          }

          if (process.env.DEBUG) {
            let requestInfo = {
              url: requestParams.url,
              method: requestParams.method,
              headers: requestParams.headers
            };
            if (requestParams.json && typeof requestParams.json !== 'boolean') {
              requestInfo.json = requestParams.json;
            }

            // If "json" is set to an object, it will be serialised and sent as body and the value of the "body" attribute will be ignored.
            if (requestParams.body && typeof requestParams.json !== 'object') {
              if (process.env.DEBUG.indexOf('http:full_body') > -1) {
                // Show the entire body
                requestInfo.body = requestParams.body;
              } else {
                // Only show the beginning of long bodies
                requestInfo.body = requestParams.body.substring(0, 512);
                if (requestParams.body.length > 512) {
                  requestInfo.body += ' ...';
                }
              }
            }
            debug('request: %s', JSON.stringify(requestInfo, null, 2));
          }

          debugResponse(JSON.stringify(res.headers, null, 2));
          debugResponse(JSON.stringify(body, null, 2));

          engineUtil.captureOrMatch(
            params,
            res,
            context,
            function captured(err, result) {
              if (err) {
                // Run onError hooks and end the scenario:
                runOnErrorHooks(onErrorHandlers, config.processor, err, requestParams, context, ee, function(asyncErr) {
                  ee.emit('error', err.message);
                  return callback(err, context);
                });
              }

              debug('captures and matches:');
              debug(result.matches);
              debug(result.captures);

              // match and capture are strict by default:
              let haveFailedMatches = _.some(result.matches, function(v, k) {
                return !v.success && v.strict !== false;
              });

              let haveFailedCaptures = _.some(result.captures, function(v, k) {
                return v === '';
              });

              if (haveFailedMatches || haveFailedCaptures) {
                // TODO: Emit the details of each failed capture/match
              } else {
                _.each(result.matches, function(v, k) {
                  ee.emit('match', v.success, {
                    expected: v.expected,
                    got: v.got,
                    expression: v.expression,
                    strict: v.strict
                  });
                });

                _.each(result.captures, function(v, k) {
                  context.vars[k] = v;
                });
              }

              // Now run afterResponse processors
              let functionNames = _.concat(opts.afterResponse || [], params.afterResponse || []);
              async.eachSeries(
                functionNames,
                function iteratee(functionName, next) {
                  let processFunc = config.processor[functionName];
                  processFunc(requestParams, res, context, ee, function(err) {
                    if (err) {
                      return next(err);
                    }
                    return next(null);
                  });
                }, function(err) {
                  if (err) {
                    debug(err);
                    ee.emit('error', err.code || err.message);
                    return callback(err, context);
                  }

                  if (haveFailedMatches || haveFailedCaptures) {
                    // FIXME: This means only one error in the report even if multiple captures failed for the same request.
                    return callback(new Error('Failed capture or match'), context);
                  }

                  return callback(null, context);
                });
            });
        }

        // If we aren't processing the full response, we don't need the
        // callback:
        let maybeCallback;
        if (typeof requestParams.capture === 'object' ||
            typeof requestParams.match === 'object' ||
            requestParams.afterResponse ||
            opts.afterResponse ||
            process.env.DEBUG) {
          maybeCallback = requestCallback;
        }

        if(!requestParams.url) {
          let err = new Error('an URL must be specified');

          // Run onError hooks and end the scenario
          runOnErrorHooks(onErrorHandlers, config.processor, err, requestParams, context, ee, function(asyncErr) {
            ee.emit('error', err.message);
            return callback(err, context);
          });
        }

        request(requestParams, maybeCallback)
          .on('request', function(req) {
            debugRequests("request start: %s", req.path);
            ee.emit('request');

            const startedAt = process.hrtime();

            req.on('response', function updateLatency(res) {
              let code = res.statusCode;
              const endedAt = process.hrtime(startedAt);
              let delta = (endedAt[0] * 1e9) + endedAt[1];
              debugRequests("request end: %s", req.path);
              ee.emit('response', delta, code, context._uid);
            });
          }).on('end', function() {
            context._successCount++;

            if (!maybeCallback) {
              callback(null, context);
            } // otherwise called from requestCallback
          }).on('error', function(err) {
            debug(err);

            // Run onError hooks and end the scenario
            runOnErrorHooks(onErrorHandlers, config.processor, err, requestParams, context, ee, function(asyncErr) {
              let errCode = err.code || err.message;
              ee.emit('error', errCode);
              return callback(err, context);
            });
          });
      }); // eachSeries
Example #13
0
var runPresetTest = function(args) {
    //  try catch known error to display more info details
    try {

        //  detect if testenv config file exists
        var testenvJSON = path.resolve(process.cwd(), 'testenv.json');

        //  if there is, read the configuration
        var presets = require(testenvJSON);

        //  resolve preset path from relative to absolute
        presets = _.mapValues(presets, function (str_array) {
            return _.map(str_array, function (str) {
                return path.resolve(process.cwd(), str);
            })
        })

        //  get options
        var opts = _.pickBy(args.opts, function (optValue) {
            return optValue;
        })
        
        //  init variable for further use
        var testConfigFiles, testName;

        //  depends on options, run corresponding preset
        if (_.isEqual(opts, {c: true, u: true})) {
            testName = 'client side unit test';
            testConfigFiles = presets.client_uni;
        } else if (_.isEqual(opts, {c: true, i: true})) {
            testName = 'client side integration test';
            testConfigFiles = presets.client_int;
        } else if (_.isEqual(opts, {c: true, e: true})) {
            testName = 'client side end-to-end test';
            testConfigFiles = presets.client_e2e;
        } else if (_.isEqual(opts, {s: true, u: true})) {
            testName = 'server side unit test';
            testConfigFiles = presets.server_uni;
        } else if (_.isEqual(opts, {s: true, i: true})) {
            testName = 'server side integration test';
            testConfigFiles = presets.server_int;
        } else if (_.isEqual(opts, {s: true, e: true})) {
            testName = 'server side end-to-end test';
            testConfigFiles = presets.server_e2e;
        } else if (_.isEqual(opts, {c: true})) {
            testName = 'client side test';
            testConfigFiles = presets.client;
        } else if (_.isEqual(opts, {s: true})) {
            testName = 'server side test';
            testConfigFiles = presets.server;
        } else if (_.isEqual(opts, {a: true})) {
            testName = 'all test';
            testConfigFiles = presets.all;
        } else {
            //  do nothing
             console.log('ERROR: Unknown Options!');
        }

        if(testConfigFiles) {
            new TestRunner(testConfigFiles, function done() {
                console.log('End ' + testName);
                process.exit(0);
            });
        } else {
            console.log('WARN: No test was run!');
        }
    }
    catch (err) {
        if (/(Cannot find module \')(.*)(testenv\.json\')/.test(err.message)) {
            //  missing testenv config file, display the 'init' command for creating a new testenv config file
            console.log('\nMissing testenv.json file. Use \'testenv init\' to create.\n');
        } else {
            //  other unknown error, log it
            util.logError(err);
        }
    }
}
Example #14
0
 function getConfigColorMapping() {
   return _.mapValues(config.get('visualization:colorMapping'), standardizeColor);
 }
Example #15
0
 addLevels: function (levels) {
   logger = _.defaults(logger, _.mapValues(levels, makeLogFunction));
 }
function parseParams(params) {
  return _.mapValues(params, parseObject);
}
import { capitalize, mapValues } from 'lodash';

mapValues({ 'a': 'b' }, capitalize);
Example #18
0
 .then(function (catalogsLeads) {
   return _.mapValues(leads, function (lead, url) {
     return catalogsLeads[url] || lead;
   });
 });
Example #19
0
export const flattenState = (state: State) =>
	_.mapValues(state, (piece: Field | any): any => {
		if (typeof piece !== 'object') return piece
		if (piece.__flum) return piece.value
		return flattenState(piece)
	})
// Creates a new LinkedDataFragmentsServer
function LinkedDataFragmentsServer(options) {
  // Create the HTTP server
  var server = http.createServer(), sockets = 0;
  for (var member in LinkedDataFragmentsServer.prototype)
    server[member] = LinkedDataFragmentsServer.prototype[member];

  // Assign settings
  server._sockets = {};
  server._baseUrl = _.mapValues(url.parse(options.baseURL || '/'), function (value, key) {
    return value && !/^(?:href|path|search)$/.test(key) ? value : undefined;
  });
  server._log = options.log || console.error;
  server._accesslogger = options.accesslogger || _.noop;
  server._routers = options.routers || [];
  server._datasources = options.datasources || {};
  server._prefixes = options.prefixes || {};
  server._writers = [];
  server._assetsPath = options.assetsPath || '/assets/',
  server._assetsMatcher = new RegExp('^' + toRegExp(server._assetsPath) + '(.+)|^/(\\w*)\\.ico$');
  server._deferencePaths = options.dereference || {};
  if (!_.isEmpty(server._deferencePaths))
    server._dereferenceMatcher = new RegExp('^(' + Object.keys(server._deferencePaths)
                                                   .map(toRegExp).join('|') + ')');

  // Prepare writers and their MIME types
  for (var mimeTypes in options.writers) {
    // The object value is a writer, the key is a list of MIME types
    var writer = options.writers[mimeTypes];
    mimeTypes = mimeTypes.split(/[,;]/);
    // Create a settings object for each writer
    mimeTypes.forEach(function (mimeType, index) {
      var isUniversalType = mimeType === '*/*',
          specificType = isUniversalType ? (mimeTypes[index ? 0 : 1] || 'text/plain') : mimeType,
          isTextualType = /^text\/|\/(?:json|xml)$/.test(specificType);
      server._writers.push({
        writer: writer,
        type: mimeType, // for content negotiation
        mimeType: isTextualType ? specificType + ';charset=utf-8' : specificType, // for response
        quality: isUniversalType ? 1.0 : 0.8,
      });
    });
  }

  // Read assets into memory
  var assetsFolder = options.assetsFolder || path.join(__dirname, '../assets/');
  server._assets = fs.readdirSync(assetsFolder).reduce(function (assets, filename) {
    var assetType = mime.lookup(filename);
    return assets[filename.replace(/[.][^.]+$/, '')] = {
      type: assetType.indexOf('text/') ? assetType : assetType + ';charset=utf-8',
      contents: fs.readFileSync(path.join(assetsFolder, filename)),
    }, assets;
  }, {});

  // Attach event listeners
  server.on('error', function (error) { server._sendError(error); });
  server.on('request', function (request, response) {
    server._accesslogger(request, response);
    try { server._handleRequest(request, response); }
    catch (error) { server._sendError(request, response, error); }
  });
  server.on('connection', function (socket) {
    var socketId = sockets++;
    server._sockets[socketId] = socket;
    socket.on('close', function () { delete server._sockets[socketId]; });
  });
  return server;
}
Example #21
0
'use strict';

const _ = require('lodash');

const lib = {
	Utils: require('./build/utils'),
	AccessToken: require('./build/models/access-token'),
	Client: require('./build/models/client'),
	Group: require('./build/models/group'),
	Message: require('./build/models/message'),
	Organization: require('./build/models/organization'),
	RefreshToken: require('./build/models/refresh-token'),
	RequestToken: require('./build/models/request-token'),
	Room: require('./build/models/room'),
	User: require('./build/models/user')
};

module.exports = _.mapValues(lib, val => {
	if (val.__esModule && _.has(val, 'default')) {
		return val.default;
	}
	return val;
});
var writeHTML = function () {
	'use strict';
  pageClient.emit('messages', 'Generating result page');

	var deferred = Q.defer();
	var graph_height = 1000 + (lo.size(coverage_stats) * 10);
	var html = '<head>\n  <!-- Plotly.js -->\n  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>\n</head>\n\n<body>\n  \n  <div id="myDiv" style="width: 100%; height: '+graph_height+'px;"><!-- Plotly chart will be drawn inside this DIV --></div>\n  <script>\n    <!-- JAVASCRIPT CODE GOES HERE -->';
	var script_end = ';\nvar layout = {\n\ttitle: \'Test Coverage\',\n\thovermode:\'closest\',\n\tbarmode:\'overlay\',\n\tmargin: {\n\t\tl:250\n\t},\tshowlegend: true,\n\tlegend: {\n\t\tx: 0,\n\t\ty: 100\n\t}\n\t};\nPlotly.newPlot(\'myDiv\', data, layout);</script>'
	var html_end = '</body>';

    var temp = lo.mapValues(coverage_stats, 'Coverage');
    console.log(temp);
    var keys = lo.keys(temp).sort().reverse();
    // Remove the Total Org Coverage from the keys
    lo.pull(keys,'Total Org Coverage');
    // Add it back at the end so it displays at the top of the graph
    keys.push('Total Org Coverage');
    var keys_str = '';
    var values_str = '';
    var sfCover = '';
    var orgCover = '';
    try {
	    lo.forEach(keys,function(key) {
		    // console.log('key:' + keys_str.length + ', value:' + values_str.length);
		    // console.log('sfCover:' + sfCover.length + ', orgCover:' + orgCover.length);
	    	if (keys_str.length == 0) {
	    		keys_str = keys_str + '\'' + key + '\'';
	    	} else {
	    		keys_str = keys_str + ', ' + '\'' + key + '\'';
	    	}

	    	var value = temp[key];
	    	if (values_str.length == 0) {
	    		values_str = values_str + value;
	    		sfCover = sfCover + 75;
	    		orgCover = orgCover + 85;
	    	} else {
	    		values_str = values_str + ', ' + value;
	    		sfCover = sfCover + ', ' + 75;
	    		orgCover = orgCover + ', ' + 85;
	    	}
	    });
	} catch (error) {
	    console.log('key:' + keys_str + ', values_str:' + values_str + ', sfCover:' + sfCover + ', orgCover:' + orgCover);

		deferred.reject(new Error(error));
		return deferred.promise;
	}

    var data = '\nvar trace1={\n\
    	name:\'Code Coverage %\',\n\
    	//hoverinfo:"x+y",\n\
    	y:[' + keys_str + '],\n\
    	x:[' + values_str + '],\n\
    	type: \'bar\',\n\
    	orientation:\'h\',\n\
    	showlegend: false\n\
    };\n\
    var trace2={\n\
    	name:\'Salesforce Required Coverage Level\',\n\
    	//hoverinfo:\'Salesforce Required Coverage Level\',\n\
    	y:[' + keys_str + '],\n\
    	x:[' + sfCover + '],\n\
    	type: \'scatter\',\n\
		mode:\'lines\',\n\
		showlegend: true,\n\
		marker: {\n\
			color: \'red\',\n\
			width: 3\n\
		}\n\
    };\n\
    var trace3={\n\
		name:\'Org Required Coverage Level\',\n\
    	y:[' + keys_str + '],\n\
    	x:[' + orgCover + '],\n\
    	type: \'scatter\',\n\
		mode:\'lines\',\n\
		showlegend: true,\n\
		marker: {\n\
			color: \'green\',\n\
			width: 3\n\
		}\n\
    };\n\
    var data=[trace1,trace2,trace3]';

    var failedTests = '';
    lo.forEach(test_class_map, function(testClass, id) {
    	lo.forEach(testClass.failures, function(failure) {
	    	failedTests = failedTests + '\t<tr><td>' + testClass.name + '</td><td>' + failure.MethodName + '</td><td>' + failure.Message + '</td><td>' + failure.StackTrace+ '</td></tr>';
    	})
    });
    if (failedTests.length > 0) {
    	failedTests = '<br/><H1>ERROR - Tests have failed</H1><Table><TH>Test Class Name</TH><TH>Test Method Name</TH><TH>Message</TH><TH>Stack Trace</TH>' + failedTests + '</Table>';
    }

    var uncompiledClasses = '';
    if (lo.size(classes_to_be_recompiled) > 0) {
    	uncompiledClasses = '<br/><H1>WARNING these classes need to be recompiled in the org to allow proper Test Coverage to be calculated.</H1><br/><ul>\n';

    	lo.forEach(classes_to_be_recompiled,function(value, key) {
    		uncompiledClasses = uncompiledClasses + '\t<li>' + key + '</li>';
    	});
    	uncompiledClasses = uncompiledClasses + '</ul><br/>\n';
    }

    if (html_testClasses_seeAllData.length > 0) {
    	html_testClasses_seeAllData = '<br/><H1>WARNING these Test Classes are using See All Data annotation</H1><br/><ul>\n' +
    									html_testClasses_seeAllData + '</ul><br/>\n';
    }

    fs.writeFile(HTMLFilename, html + data + script_end + failedTests + html_testClasses_seeAllData + uncompiledClasses + html_end);
    errorOccurred = false;
    deferred.resolve();
    return deferred.promise;
}
Example #23
0
function ContextAppController($scope, config, Private, timefilter) {
  const queryParameterActions = Private(QueryParameterActionsProvider);
  const queryActions = Private(QueryActionsProvider);

  timefilter.disableAutoRefreshSelector();
  timefilter.disableTimeRangeSelector();

  this.state = createInitialState(
    parseInt(config.get('context:step'), 10),
    getFirstSortableField(this.indexPattern, config.get('context:tieBreakerFields')),
    this.discoverUrl,
  );

  this.actions = _.mapValues({
    ...queryParameterActions,
    ...queryActions,
  }, (action) => (...args) => action(this.state)(...args));

  this.constants = {
    FAILURE_REASONS,
    LOADING_STATUS,
  };

  $scope.$watchGroup([
    () => this.state.rows.predecessors,
    () => this.state.rows.anchor,
    () => this.state.rows.successors,
  ], (newValues) => this.actions.setAllRows(...newValues));

  /**
   * Sync properties to state
   */
  $scope.$watchCollection(
    () => ({
      ...(_.pick(this, QUERY_PARAMETER_KEYS)),
      indexPatternId: this.indexPattern.id,
    }),
    (newQueryParameters) => {
      const { queryParameters } = this.state;
      if (
        (newQueryParameters.indexPatternId !== queryParameters.indexPatternId)
        || (newQueryParameters.anchorUid !== queryParameters.anchorUid)
        || (!_.isEqual(newQueryParameters.sort, queryParameters.sort))
      ) {
        this.actions.fetchAllRowsWithNewQueryParameters(_.cloneDeep(newQueryParameters));
      } else if (
        (newQueryParameters.predecessorCount !== queryParameters.predecessorCount)
        || (newQueryParameters.successorCount !== queryParameters.successorCount)
        || (!_.isEqual(newQueryParameters.filters, queryParameters.filters))
      ) {
        this.actions.fetchContextRowsWithNewQueryParameters(_.cloneDeep(newQueryParameters));
      }
    },
  );

  /**
   * Sync state to properties
   */
  $scope.$watchCollection(
    () => ({
      predecessorCount: this.state.queryParameters.predecessorCount,
      successorCount: this.state.queryParameters.successorCount,
    }),
    (newParameters) => {
      _.assign(this, newParameters);
    },
  );
}
Example #24
0
 commonContent(lang = 'en') {
     this.i18next.changeLanguage(lang);
     const common = require('app/resources/en/translation/common');
     return mapValues(common, (value, key) => this.i18next.t(`common.${key}`));
 }
Example #25
0
WLValidationError.prototype.__defineGetter__('messages', function(){
  return _.mapValues(this.invalidAttributes, function (rules, attrName) {
    return _.pluck(rules, 'message');
  });
});
Example #26
0
}

function buildComponent (widget, name, prefix) {
  var mixins = [
    KendoWidgetMixin(kendoWidgetName(prefix, name))
  ];
  if (widgetMixins[name]) {
    mixins.push(widgetMixins[name]);
  }
  return React.createClass({
    mixins: mixins
  });
}

var KendoUi = _.mapValues(kendo.ui, function (widget, name) {
  return buildComponent(widget, name, '');
});

var KendoDataViz = _.mapValues(kendo.dataviz && kendo.dataviz.ui, function (widget, name) {
  return buildComponent(widget, name, '');
});

var KendoMobileUi = _.mapValues(kendo.mobile && kendo.mobile.ui, function (widget, name) {
  return buildComponent(widget, name, 'Mobile');
});

module.exports = _.extend({
    Template: require('./KendoTemplate'),
    mobile: KendoMobileUi,
    dataviz: KendoDataViz
  },
Example #27
0
const transformKeyValueForUpdate = (className, restKey, restValue, parseFormatSchema) => {
  // Check if the schema is known since it's a built-in field.
  var key = restKey;
  var timeField = false;
  switch(key) {
  case 'objectId':
  case '_id':
    key = '_id';
    break;
  case 'createdAt':
  case '_created_at':
    key = '_created_at';
    timeField = true;
    break;
  case 'updatedAt':
  case '_updated_at':
    key = '_updated_at';
    timeField = true;
    break;
  case 'sessionToken':
  case '_session_token':
    key = '_session_token';
    break;
  case 'expiresAt':
  case '_expiresAt':
    key = 'expiresAt';
    timeField = true;
    break;
  case '_rperm':
  case '_wperm':
    return {key: key, value: restValue};
    break;
  }

  if ((parseFormatSchema.fields[key] && parseFormatSchema.fields[key].type === 'Pointer') || (!parseFormatSchema.fields[key] && restValue && restValue.__type == 'Pointer')) {
    key = '_p_' + key;
  }

  // Handle atomic values
  var value = transformTopLevelAtom(restValue);
  if (value !== CannotTransform) {
    if (timeField && (typeof value === 'string')) {
      value = new Date(value);
    }
    return {key, value};
  }

  // Handle arrays
  if (restValue instanceof Array) {
    value = restValue.map(transformInteriorValue);
    return {key, value};
  }

  // Handle update operators
  if (typeof restValue === 'object' && '__op' in restValue) {
    return {key, value: transformUpdateOperator(restValue, false)};
  }

  // Handle normal objects by recursing
  value = _.mapValues(restValue, transformInteriorValue);
  return {key, value};
}
Example #28
0
function createObjectCollection(count) {
  return _.mapValues(_.shuffle(_.times(count)));
}
Example #29
0
    componentWillReceiveProps(newProps) {
        this.initBisector(newProps);
    },
    initBisector(props) {
        this.setState({bisectX: d3.bisector(d => accessor(this.props.getValue.x)(d)).left});
    },

    getHovered(x, y) {
        const closestDataIndex = this.state.bisectX(this.props.data, x);
        //console.log(closestDataIndex, this.props.data[closestDataIndex]);
        return this.props.data[closestDataIndex];
    },

    render() {
        const {data, getValue, scale} = this.props;
        const accessors = _.mapValues(getValue, accessor);
        const points = _.map(data, d => [scale.x(accessors.x(d)), scale.y(accessors.y(d))]);
        const pathStr = pointsToPathStr(points);

        return <g className={this.props.name}>
            <path d={pathStr} />
        </g>;
    }
});

function pointsToPathStr(points) {
    // takes array of points in [[x, y], [x, y]... ] format
    // returns SVG path string in "M X Y L X Y" format
    // https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands
    return _.map(points, ([x, y], i) => {
        const command = (i === 0) ? 'M' : 'L';
Example #30
0
module.exports = function buildRequest (_req) {
  _req = _req||{};

  var req;

  // If `_req` appears to be a stream (duck-typing), then don't try
  // and turn it into a mock stream again.
  if (typeof _req === 'object' && _req.read) {
    req = _req;
  }
  else {

    // TODO: send a PR to mock-req with a fix for this
    if (_req.headers && typeof _req.headers === 'object') {
      // Strip undefined headers
      _.each(_req.headers, function (headerVal, headerKey) {
        if (_.isUndefined(headerVal)){
          delete _req.headers[headerKey];
        }
      });
      // Make sure all remaining headers are strings
      _req.headers = _.mapValues(_req.headers, function (headerVal, headerKey) {
        if (typeof headerVal !== 'string') {
          headerVal = ''+headerVal+'';
        }
        return headerVal;
      });
    }

    // Create a mock IncomingMessage stream.
    req = new MockReq({
      method: _req && (_.isString(_req.method) ? _req.method.toUpperCase() : 'GET'),
      headers: _req && _req.headers || {},
      url: _req && _req.url
    });

    // Now pump client request body to the mock IncomingMessage stream (req)
    // Req stream ends automatically if this is a GET or HEAD or DELETE request
    // (since there is no request body in that case) so no need to do it again.
    if (req.method !== 'GET' && req.method !== 'HEAD' && req.method !== 'DELETE') {

      // Only write the body if there IS a body.
      if (req.body) {
        req.write(req.body);
      }
      req.end();
    }
  }

  // Track request start time
  req._startTime = new Date();

  // TODO: add all the other methods in core

  // Provide defaults for other request state and methods
  req = defaultsDeep(req, {
    params: [],
    query: (_req && _req.query) || {},
    body: (_req && _req.body) || {},
    param: function(paramName, defaultValue) {

      var key, params = {};
      for (key in (req.params || {}) ) {
        params[key] = params[key] || req.params[key];
      }
      for (key in (req.query || {}) ) {
        params[key] = params[key] || req.query[key];
      }
      for (key in (req.body || {}) ) {
        params[key] = params[key] || req.body[key];
      }

      // Grab the value of the parameter from the appropriate place
      // and return it
      if (typeof params[paramName] !== 'undefined') {
        return params[paramName];
      } else {
        return defaultValue;
      }
      
    },
    wantsJSON: (_req && _req.wantsJSON) || true,
    method: 'GET'
  }, _req||{});

  return req;
};