defineMapper (name, opts) {
    // For backwards compatibility with defineResource
    if (utils.isObject(name)) {
      opts = name
      name = opts.name
    }
    if (!utils.isString(name)) {
      throw utils.err(`${DOMAIN}#defineMapper`, 'name')(400, 'string', name)
    }

    // Default values for arguments
    opts || (opts = {})
    // Set Mapper#name
    opts.name = name
    opts.relations || (opts.relations = {})

    // Check if the user is overriding the datastore's default mapperClass
    const mapperClass = opts.mapperClass || this.mapperClass
    delete opts.mapperClass

    // Apply the datastore's defaults to the options going into the mapper
    utils.fillIn(opts, this.mapperDefaults)

    // Instantiate a mapper
    const mapper = this._mappers[name] = new mapperClass(opts) // eslint-disable-line
    mapper.relations || (mapper.relations = {})
    // Make sure the mapper's name is set
    mapper.name = name
    // All mappers in this datastore will share adapters
    mapper._adapters = this.getAdapters()

    mapper.datastore = this

    mapper.on('all', (...args) => this._onMapperEvent(name, ...args))
    mapper.defineRelations()

    return mapper
  }
Create a new mapper and register it in this container.

@example <caption>Container#defineMapper</caption>
// import { Container } from 'js-data';
const JSData = require('js-data');
const { Container } = JSData;
console.log('Using JSData v' + JSData.version.full);

const store = new Container({
  mapperDefaults: { foo: 'bar' }
});
// Container#defineMapper returns a direct reference to the newly created
// Mapper.
const UserMapper = store.defineMapper('user');
console.log(UserMapper === store.getMapper('user'));
console.log(UserMapper === store.as('user').getMapper());
console.log(UserMapper.foo);

@method Container#defineMapper
@param {string} name Name under which to register the new {@link Mapper}.
{@link Mapper#name} will be set to this value.
@param {object} [opts] Configuration options. Passed to
{@link Container#mapperClass} when creating the new {@link Mapper}.
@returns {Mapper} The newly created instance of {@link Mapper}.
@see Container#as
@since 3.0.0