How to use the parse/node.Parse._encode function in parse

To help you get started, we’ve selected a few parse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github parse-community / parse-server / src / Adapters / Storage / Mongo / MongoTransform.js View on Github external
case '_tombstone':
        break;
      case '_session_token':
        restObject['sessionToken'] = mongoObject[key];
        break;
      case 'updatedAt':
      case '_updated_at':
        restObject['updatedAt'] = Parse._encode(new Date(mongoObject[key])).iso;
        break;
      case 'createdAt':
      case '_created_at':
        restObject['createdAt'] = Parse._encode(new Date(mongoObject[key])).iso;
        break;
      case 'expiresAt':
      case '_expiresAt':
        restObject['expiresAt'] = Parse._encode(new Date(mongoObject[key]));
        break;
      default:
        // Check other auth data keys
        var authDataMatch = key.match(/^_auth_data_([a-zA-Z0-9_]+)$/);
        if (authDataMatch) {
          var provider = authDataMatch[1];
          restObject['authData'] = restObject['authData'] || {};
          restObject['authData'][provider] = mongoObject[key];
          break;
        }

        if (key.indexOf('_p_') == 0) {
          var newKey = key.substring(3);
          var expected;
          if (schema && schema.getExpectedType) {
            expected = schema.getExpectedType(className, newKey);
github parse-community / parse-server / src / Adapters / Storage / Mongo / MongoTransform.js View on Github external
break;
      case '_acl':
      case '_email_verify_token':
      case '_perishable_token':
      case '_tombstone':
        break;
      case '_session_token':
        restObject['sessionToken'] = mongoObject[key];
        break;
      case 'updatedAt':
      case '_updated_at':
        restObject['updatedAt'] = Parse._encode(new Date(mongoObject[key])).iso;
        break;
      case 'createdAt':
      case '_created_at':
        restObject['createdAt'] = Parse._encode(new Date(mongoObject[key])).iso;
        break;
      case 'expiresAt':
      case '_expiresAt':
        restObject['expiresAt'] = Parse._encode(new Date(mongoObject[key]));
        break;
      default:
        // Check other auth data keys
        var authDataMatch = key.match(/^_auth_data_([a-zA-Z0-9_]+)$/);
        if (authDataMatch) {
          var provider = authDataMatch[1];
          restObject['authData'] = restObject['authData'] || {};
          restObject['authData'][provider] = mongoObject[key];
          break;
        }

        if (key.indexOf('_p_') == 0) {
github parse-community / parse-server / spec / rest.spec.js View on Github external
it('handles array, object, date', done => {
    const now = new Date();
    const obj = {
      array: [1, 2, 3],
      object: { foo: 'bar' },
      date: Parse._encode(now),
    };
    rest
      .create(config, auth.nobody(config), 'MyClass', obj)
      .then(() =>
        database.adapter.find(
          'MyClass',
          {
            fields: {
              array: { type: 'Array' },
              object: { type: 'Object' },
              date: { type: 'Date' },
            },
          },
          {},
          {}
        )
github parse-community / parse-server / src / Adapters / Storage / Mongo / MongoTransform.js View on Github external
case 'boolean':
    case 'undefined':
      return mongoObject;
    case 'symbol':
    case 'function':
      throw 'bad value in mongoObjectToParseObject';
    case 'object': {
      if (mongoObject === null) {
        return null;
      }
      if (mongoObject instanceof Array) {
        return mongoObject.map(nestedMongoObjectToNestedParseObject);
      }

      if (mongoObject instanceof Date) {
        return Parse._encode(mongoObject);
      }

      if (mongoObject instanceof mongodb.Long) {
        return mongoObject.toNumber();
      }

      if (mongoObject instanceof mongodb.Double) {
        return mongoObject.value;
      }

      if (BytesCoder.isValidDatabaseObject(mongoObject)) {
        return BytesCoder.databaseToJSON(mongoObject);
      }

      const restObject = {};
      if (mongoObject._rperm || mongoObject._wperm) {
github parse-community / parse-server / src / Adapters / Storage / Mongo / MongoTransform.js View on Github external
case 'undefined':
  case 'symbol':
  case 'function':
    throw 'bad value in untransformObject';
  case 'object':
    if (mongoObject === null) {
      return null;
    }
    if (mongoObject instanceof Array) {
      return mongoObject.map(arrayEntry => {
        return untransformObject(schema, className, arrayEntry, true);
      });
    }

    if (mongoObject instanceof Date) {
      return Parse._encode(mongoObject);
    }

    if (mongoObject instanceof mongodb.Long) {
      return mongoObject.toNumber();
    }

    if (mongoObject instanceof mongodb.Double) {
      return mongoObject.value;
    }

    if (BytesCoder.isValidDatabaseObject(mongoObject)) {
      return BytesCoder.databaseToJSON(mongoObject);
    }

    var restObject = untransformACL(mongoObject);
    for (var key in mongoObject) {
github parse-community / parse-server / src / Adapters / Storage / Mongo / MongoTransform.js View on Github external
case 'boolean':
    case 'undefined':
      return mongoObject;
    case 'symbol':
    case 'function':
      throw 'bad value in nestedMongoObjectToNestedParseObject';
    case 'object':
      if (mongoObject === null) {
        return null;
      }
      if (mongoObject instanceof Array) {
        return mongoObject.map(nestedMongoObjectToNestedParseObject);
      }

      if (mongoObject instanceof Date) {
        return Parse._encode(mongoObject);
      }

      if (mongoObject instanceof mongodb.Long) {
        return mongoObject.toNumber();
      }

      if (mongoObject instanceof mongodb.Double) {
        return mongoObject.value;
      }

      if (BytesCoder.isValidDatabaseObject(mongoObject)) {
        return BytesCoder.databaseToJSON(mongoObject);
      }

      if (
        Object.prototype.hasOwnProperty.call(mongoObject, '__type') &&
github parse-community / parse-server / src / Adapters / Storage / Mongo / MongoTransform.js View on Github external
new Date(mongoObject[key])
            ).iso;
            break;
          case 'createdAt':
          case '_created_at':
            restObject['createdAt'] = Parse._encode(
              new Date(mongoObject[key])
            ).iso;
            break;
          case 'expiresAt':
          case '_expiresAt':
            restObject['expiresAt'] = Parse._encode(new Date(mongoObject[key]));
            break;
          case 'lastUsed':
          case '_last_used':
            restObject['lastUsed'] = Parse._encode(
              new Date(mongoObject[key])
            ).iso;
            break;
          case 'timesUsed':
          case 'times_used':
            restObject['timesUsed'] = mongoObject[key];
            break;
          case 'authData':
            if (className === '_User') {
              log.warn(
                'ignoring authData in _User as this key is reserved to be synthesized of `_auth_data_*` keys'
              );
            } else {
              restObject['authData'] = mongoObject[key];
            }
            break;