How to use the js-data.utils.deepMixIn function in js-data

To help you get started, we’ve selected a few js-data 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 Wikodit / js-data-jsonapi-light / src / serializer.ts View on Github external
// Just cache a pointer to relations for the Resource
  mapperCacheRelationByField(mapper);

  let output:any = { data: { type: mapper.name } };

  // Work for update or create, if an id is given, server should accept it
  if (id) output.data.id = id;

  let relationships:any = {};
  let attributes:any = {};

  // opts.changes is there when update method is PATCH
  // in this case we change only what has changed
  if (!opts.forceReplace && opts.changes && id) {
    data = utils.deepMixIn(
      utils.deepMixIn({}, opts.changes.changed),
      opts.changes.added
    );
  }

  // @todo For the moment sending hasMany items is not supported and maybe
  // shouldn't be supported for security reasons (cf. JSON Api Spec)
  if (opts.forceRelationshipsInAttributes !== true) {
    for (let key in data) {
      let relation:any = mapper.relationByFieldId[key];
      
      // No relations means a simple attribute
      if (!relation) {
        attributes[key] = data[key];
        continue;
      }
github Wikodit / js-data-jsonapi-light / src / main.ts View on Github external
constructor(options?:any) {
    options = utils.deepMixIn({
      // Enable the possibility to retrieve more informations in the promise of
      // a response.
      // compositePromiseResponse: false
    }, options || {})

    if (!options.store) {
      throw new Error('JsonApiAdapter needs to be given a store option.')
    }

    var selfWrapper:any = {};

    options.serialize = function(wrapper:any):any{
      return function(mapper:any, data:any, opts:any){
        let 
          beforeSerialize = opts.beforeSerialize || mapper.beforeSerialize || wrapper.self.options.beforeSerialize,
          afterSerialize = opts.afterSerialize || mapper.afterSerialize || wrapper.self.options.afterSerialize;
github Wikodit / js-data-jsonapi-light / src / serializer.ts View on Github external
// Just cache a pointer to relations for the Resource
  mapperCacheRelationByField(mapper);

  let output:any = { data: { type: mapper.name } };

  // Work for update or create, if an id is given, server should accept it
  if (id) output.data.id = id;

  let relationships:any = {};
  let attributes:any = {};

  // opts.changes is there when update method is PATCH
  // in this case we change only what has changed
  if (!opts.forceReplace && opts.changes && id) {
    data = utils.deepMixIn(
      utils.deepMixIn({}, opts.changes.changed),
      opts.changes.added
    );
  }

  // @todo For the moment sending hasMany items is not supported and maybe
  // shouldn't be supported for security reasons (cf. JSON Api Spec)
  if (opts.forceRelationshipsInAttributes !== true) {
    for (let key in data) {
      let relation:any = mapper.relationByFieldId[key];
      
      // No relations means a simple attribute
      if (!relation) {
        attributes[key] = data[key];
        continue;
      }
github Wikodit / js-data-jsonapi-light / src / adapter.ts View on Github external
constructor(options?:any) {
    options = utils.deepMixIn({
      // Some default
    }, options || {})

    if (options.serialize || options.deserialize) {
      throw new Error(ERROR.PREVENT_SERIALIZE_DESERIALIZE_OPTIONS)
    }

    super(options);

    this.options = options;

    this.serialize = wrapSerialize(this);
    this.deserialize = wrapDeserialize(this);
  }
github js-data / js-data-http / src / index.js View on Github external
HTTP (config, opts) {
    const start = new Date()
    opts || (opts = {})
    const payload = config.data
    const cache = config.cache
    const timeout = config.timeout
    const params = config.params
    config = utils.copy(config, null, null, null, ['data', 'cache', 'timeout', 'params']) // params could have data, cache, timeout
    config.params = utils.copy(params)
    config = utils.deepMixIn(config, this.httpConfig)
    config.data = payload
    config.cache = cache
    if (timeout !== undefined) {
      config.timeout = timeout
    }
    if (this.forceTrailingSlash && config.url[config.url.length - 1] !== '/') {
      config.url += '/'
    }
    config.method = config.method.toUpperCase()
    const suffix = config.suffix || opts.suffix || this.suffix
    if (suffix && config.url.substr(config.url.length - suffix.length) !== suffix) {
      config.url += suffix
    }

    const logResponse = (data) => {
      const str = `${start.toUTCString()} - ${config.method.toUpperCase()} ${config.url} - ${data.status} ${(new Date().getTime() - start.getTime())}ms`
github js-data / js-data-firebase / src / index.js View on Github external
.then((currentVal) => {
        if (!currentVal) {
          throw new Error('Not Found')
        }
        const newVal = opts.deepMerge !== false ? utils.deepMixIn(currentVal, props) : props
        return itemRef.set(newVal)
      })
      .then(() => this._once(itemRef))
github js-data / js-data-http / src / index.js View on Github external
findAll (mapper, query, opts) {
    query || (query = {})
    opts || (opts = {})
    opts.params = this.getParams(opts)
    opts.suffix = this.getSuffix(mapper, opts)
    utils.deepMixIn(opts.params, query)
    opts.params = this.queryTransform(mapper, opts.params, opts)
    return Adapter.prototype.findAll.call(this, mapper, query, opts)
  },
github js-data / js-data-firebase / src / index.js View on Github external
      records.forEach((record) => utils.deepMixIn(record, props))
      return this._upsertBatch(mapper, records, opts)
github GoogleCloudPlatform / js-data-cloud-datastore / src / index.js View on Github external
records.forEach((record, i) => {
        if (!record) {
          return;
        }
        const id = utils.get(record, idAttribute);
        if (!utils.isUndefined(id)) {
          utils.deepMixIn(record, props[i]);
          entities.push({
            method: 'update',
            key: this.datastore.key([this.getKind(mapper, opts), id]),
            data: record
          });
          _records.push(record);
        }
      });
      if (!_records.length) {
github js-data / js-data-http / src / index.js View on Github external
mapper[name] = function (id, _opts) {
      _opts = _opts || {}
      if (utils.isObject(id)) {
        _opts = id
      }
      utils.fillIn(_opts, opts)
      let adapter = this.getAdapter(_opts.adapter || this.defaultAdapter || 'http')
      const config = {}
      config.mapper = this.name
      utils.deepMixIn(config, _opts)
      config.method = config.method || 'GET'
      if (typeof _opts.getEndpoint === 'function') {
        config.url = _opts.getEndpoint(this, _opts)
      } else {
        let args = [
          _opts.basePath || this.basePath || adapter.basePath,
          adapter.getEndpoint(this, id, _opts)
        ]
        if (utils.isSorN(id)) {
          args.push(id)
        }
        args.push(opts.pathname || name)
        config.url = makePath.apply(null, args)
      }
      return utils.resolve(config)
        .then(_opts.request)