Exemplo n.º 1
0
Arquivo: Sync.js Projeto: LavN/mig
	var createColumn = function (collection, prop) {
		var type;

		if (types.hasOwnProperty(prop.type)) {
			type = types[prop.type].datastoreType(prop);
		} else {
			type = Dialect.getType(collection, prop, driver);
		}

		if (type === false) {
			return false;
		}
		if (typeof type == "string") {
			type = { value : type };
		}

		if (prop.mapsTo === undefined) {
			console.log("undefined prop.mapsTo", prop, (new Error()).stack)
		}

		return {
			value  : driver.query.escapeId(prop.mapsTo) + " " + type.value,
			before : type.before
		};
	};
Exemplo n.º 2
0
Table.prototype.insert = function(docs, options, query) {
  options = options || {};

  try {
    util.assertType(docs, ['OBJECT', 'ARRAY'], query);
  }
  catch(err) {
    typeValue = util.getType(docs);
    throw new Error.ReqlRuntimeError("Cannot convert "+typeValue+" to SEQUENCE", this.frames)
  }

  var result = util.writeResult();
  var generatedKeys = [];
  var newDoc;
  if (docs instanceof Sequence) {
    for(var i=0; i<docs.length; i++) {
      newResult = this._singleInsert(docs.get(i), options, query);
      util.mergeWriteResult(result, newResult);
    }
  }
  else {
    newResult = this._singleInsert(docs, options, query);
    util.mergeWriteResult(result, newResult);
  }
  return result;
}
Exemplo n.º 3
0
			postToPublicChat: function(senderProfile, messageType, messageData, optionalMinApiVersion) {
				test.equals(senderProfile, sender);
				test.equals(messageType, TextMessage.getType());
				test.equals(messageData.text, message.text);
				test.equals(optionalMinApiVersion, minApiVersion);
				test.done();
			}
Exemplo n.º 4
0
nunjucks.runtime.suppressValue = (value, autoescape) => {
  value = original(value, autoescape);
  const type = getType(value);
  if (type === `string`) {
    value = `"${value}"`;
  } else if ([`boolean`, `number`].indexOf(type) === -1) {
    value = JSON.stringify(value);
  }
  return value;
};
Exemplo n.º 5
0
			sendMessage: function(receiverId, messageType, message, trackingData, keyboard, chatId, minApiVersion) {
				test.equals(receiverId, receiver);
				test.equals(messageType, TextMessage.getType());
				test.equals(trackingData, sampleTrackingData);
				test.equals(keyboard, sampleKeyboard);
				test.equals(chatId, sampleChatId);
				test.equals(minApiVersion, sampleMinApiVersion);
				test.equals(message.text, sampleMessage.text);
				test.done();
			}
Exemplo n.º 6
0
const getFilePath = (nodeStore, field, relativePath) => {
  const [typeName, ...selector] = field.split(`.`)

  if (typeName === `File`) return null

  const looksLikeFile =
    !path.isAbsolute(relativePath) &&
    mime.getType(relativePath) !== null &&
    // FIXME: Do we need all of this?
    mime.getType(relativePath) !== `application/x-msdownload` &&
    isRelative(relativePath) &&
    isRelativeUrl(relativePath)

  if (!looksLikeFile) return null

  const normalizedPath = slash(relativePath)
  const node = nodeStore
    .getNodesByType(typeName)
    .find(node => getFirstValueAt(node, selector) === normalizedPath)

  return node ? getAbsolutePath(nodeStore, node, normalizedPath) : null
}
Exemplo n.º 7
0
 return args => {
   return (utils.getType(content) === 'function' ?
       Promise.resolve({}).then(content) : Promise.resolve({content})).
     then(result => {
       const message = `render template${result.path ? ` ${basename(result.path)}` : ``}`;
       args._ctx = args._ctx || {stack: []};
       args._ctx.stack.push(message);
       logger.debug(message);
       return compile(result.content, data || {});
     }).
     then(result => {
       logger.debug(`template rendered:\n${result}`);
       args.content = result;
       return args;
     });
 };
	var createColumn = function (collection, name, property) {
		var type = types.hasOwnProperty(property.type)
		         ? types[property.type].datastoreType(property)
		         : Dialect.getType(collection, name, property, driver);

		if (type === false) {
			return false;
		}
		if (typeof type == "string") {
			type = { value : type };
		}

		return {
			value  : driver.query.escapeId(name) + " " + type.value,
			before : type.before
		};
	};
Exemplo n.º 9
0
    it('should return duration', function(){

      var duration = new Duration('P1000Y');

      expect(duration.getType()).to.equal('duration');
    });
Exemplo n.º 10
0
function inferGraphQLType({
  exampleValue,
  selector,
  nodes,
  types,
  ...otherArgs
}): ?GraphQLFieldConfig<*, *> {
  if (exampleValue == null || isEmptyObjectOrArray(exampleValue)) return null
  let fieldName = selector.split(`.`).pop()

  // Check this before checking for array as FileType has
  // builtin support for inferring array of files and inferred
  // array type will have faster resolver than resolving array
  // of files separately.
  if (FileType.shouldInfer(nodes, selector, exampleValue)) {
    return _.isArray(exampleValue) ? FileType.getListType() : FileType.getType()
  }

  if (Array.isArray(exampleValue)) {
    exampleValue = exampleValue[0]

    if (exampleValue == null) return null

    let inferredType = inferGraphQLType({
      ...otherArgs,
      exampleValue,
      selector,
      nodes,
      types,
    })
    invariant(
      inferredType,
      `Could not infer graphQL type for value: ${exampleValue}`
    )

    const { type, args = null, resolve = null } = inferredType

    const listType = { type: new GraphQLList(type), args }

    if (resolve) {
      // If inferredType has resolve function wrap it with Array.map
      listType.resolve = (object, args, context, resolveInfo) => {
        const fieldValue = object[fieldName]
        if (!fieldValue) {
          return null
        }

        // Field resolver expects first parameter to be plain object
        // containing key with name of field we want to resolve.
        return fieldValue.map(value =>
          resolve({ [fieldName]: value }, args, context, resolveInfo)
        )
      }
    }

    return listType
  }

  if (
    // momentjs crashes when it encounters a Symbol,
    // so check against that
    typeof exampleValue !== `symbol` &&
    DateType.shouldInfer(exampleValue)
  ) {
    return DateType.getType()
  }

  switch (typeof exampleValue) {
    case `boolean`:
      return { type: GraphQLBoolean }
    case `string`:
      return { type: GraphQLString }
    case `object`: {
      const typeName = createTypeName(fieldName)
      return {
        type: new GraphQLObjectType({
          name: typeName,
          fields: _inferObjectStructureFromNodes(
            {
              ...otherArgs,
              selector,
              nodes,
              types,
              typeName,
            },
            exampleValue
          ),
        }),
      }
    }
    case `number`:
      return is32BitInteger(exampleValue)
        ? { type: GraphQLInt }
        : { type: GraphQLFloat }
    default:
      return null
  }
}
Exemplo n.º 11
0
// Must be setup before any modules that try to use the logger are included
var logger = global.logger = require(__dirname + '/lib/logger.js');
logger.addConsoleLog({level: config.logLevel || 'info'});

var fs = require('fs'),
    redisInterface = require(__dirname + '/lib/interfaces/redis');

config.paths = {
  lib: __dirname + '/lib/',
  interfaces: __dirname + '/lib/interfaces/'
};

global.util = require(config.paths.lib + 'util');

// Construct Redis pub/sub interface
var redisPub = redisInterface.getType('store', config.pubsub.config),
    redisSub = redisInterface.getType('sub', config.pubsub.config),
    pubLoaded = _.Deferred(),
    subLoaded = _.Deferred();

redisPub.rclient.on('ready', function() { pubLoaded.resolve(); });
redisSub.rclient.on('ready', function() { subLoaded.resolve(); });

_.when(pubLoaded, subLoaded).done(function() {
  redisPub.rclient.publish('rtrest', 'ping', function(error, subscribers) {
    if(error) {
      logger.error('Failed trying to ping other running instances: ' + error);
      process.exit(1);
    }

    if(subscribers === 0) {
Exemplo n.º 12
0
function pointsToFile(nodes, key, value) {
  const looksLikeFile =
    _.isString(value) &&
    mime.getType(value) !== null &&
    // domains ending with .com
    mime.getType(value) !== `application/x-msdownload` &&
    isRelative(value) &&
    isRelativeUrl(value)

  if (!looksLikeFile) {
    return false
  }

  // Find the node used for this example.
  let node = nodes.find(n => _.get(n, key) === value)

  if (!node) {
    // Try another search as our "key" isn't always correct e.g.
    // it doesn't support arrays so the right key could be "a.b[0].c" but
    // this function will get "a.b.c".
    //
    // We loop through every value of nodes until we find
    // a match.
    const visit = (current, selector = [], fn) => {
      for (let i = 0, keys = Object.keys(current); i < keys.length; i++) {
        const key = keys[i]
        const value = current[key]

        if (value === undefined || value === null) continue

        if (typeof value === `object` || typeof value === `function`) {
          visit(current[key], selector.concat([key]), fn)
          continue
        }

        let proceed = fn(current[key], key, selector, current)

        if (proceed === false) {
          break
        }
      }
    }

    const isNormalInteger = str => /^\+?(0|[1-9]\d*)$/.test(str)

    node = nodes.find(n => {
      let isMatch = false
      visit(n, [], (v, k, selector, parent) => {
        if (v === value) {
          // Remove integers as they're for arrays, which our passed
          // in object path doesn't have.
          const normalizedSelector = selector
            .map(s => (isNormalInteger(s) ? `` : s))
            .filter(s => s !== ``)
          const fullSelector = `${normalizedSelector.join(`.`)}.${k}`
          if (fullSelector === key) {
            isMatch = true
            return false
          }
        }

        // Not a match so we continue
        return true
      })

      return isMatch
    })

    // Still no node.
    if (!node) {
      return false
    }
  }

  const rootNode = findRootNodeAncestor(node)

  // Only nodes transformed (ultimately) from a File
  // can link to another File.
  if (rootNode.internal.type !== `File`) {
    return false
  }

  const pathToOtherNode = normalize(joinPath(rootNode.dir, value))
  const otherFileExists = getNodesByType(`File`).some(
    n => n.absolutePath === pathToOtherNode
  )
  return otherFileExists
}