<|start_filename|>src/Bumblebee/Serializers/DataSerializer.js<|end_filename|>
'use strict'

const SerializerAbstract = require('./SerializerAbstract')

/**
 * DataSerializer class
 *
 * @class DataSerializer
 * @constructor
 */
class DataSerializer extends SerializerAbstract {
  /**
   * Serialize a collection of data
   * The DataSerializer will add all data under the 'data' namespace
   *
   * @param {Array} data
   */
  async collection (data) {
    return { data: data }
  }

  /**
   * Serialize a single item
   * The DataSerializer will add the item under the 'data' namespace
   *
   * @param {*} data
   */
  async item (data) {
    // if the item is an object, add it to the data property
    if (data instanceof Object) {
      return { data: data }
    }

    // If the data for this item is not a object, aka. a primitive type
    // we will just return the plain data.
    return data
  }

  /**
   * Serialize a null value
   */
  async null () {
    return null
  }

  /**
   * Serialize a meta object
   *
   * @param {Object} meta
   */
  async meta (meta) {
    return { meta: meta }
  }

  /**
   * Serialize the pagination meta data
   *
   * @param {Object} pagination
   */
  async paginator (pagination) {
    return { pagination: pagination }
  }
}

module.exports = DataSerializer


<|start_filename|>src/Bumblebee/Resources/Item.js<|end_filename|>
'use strict'

const ResourceAbstract = require('./ResourceAbstract')

/**
 * Item class
 *
 * @class Item
 */
class Item extends ResourceAbstract {
}

module.exports = Item


<|start_filename|>src/Bumblebee/Serializers/PlainSerializer.js<|end_filename|>
'use strict'

const SerializerAbstract = require('./SerializerAbstract')

/**
 * PlainSerializer class
 *
 * @class PlainSerializer
 * @constructor
 */
class PlainSerializer extends SerializerAbstract {
  /**
   * Serialize a collection of data
   * The PlainSerializer will just return the data without modification
   *
   * @param {Array} data
   */
  async collection (data) {
    return data
  }

  /**
   * Serialize a single item
   * The PlainSerializer will return the the data without modification
   *
   * @param {*} data
   */
  async item (data) {
    return data
  }

  /**
   * Serialize a null value
   */
  async null () {
    return null
  }

  /**
   * Serialize a meta object
   *
   * @param {Object} meta
   */
  async meta (meta) {
    return { meta: meta }
  }

  /**
   * Serialize the pagination meta data
   *
   * @param {Object} pagination
   */
  async paginator (pagination) {
    return { pagination: pagination }
  }
}

module.exports = PlainSerializer


<|start_filename|>src/Bumblebee/Resources/Null.js<|end_filename|>
'use strict'

const ResourceAbstract = require('./ResourceAbstract')

/**
 * Null class
 *
 * @class Null
 */
class Null extends ResourceAbstract {
  /**
   * Overwrite the constructor and set data and transformer to null
   */
  constructor () {
    super(null, null)
  }

  /**
   * Returns null, a NullResource always returns null
   */
  getData () {
    return null
  }
}

module.exports = Null


<|start_filename|>src/Bumblebee/Serializers/SerializerAbstract.js<|end_filename|>
'use strict'

/**
 * SerializerAbstract class
 *
 * @class SerializerAbstract
 */
class SerializerAbstract {
  /**
   * Serialize a collection of data
   * You must implement this method in your Serializer
   *
   * @param {Array} data
   */
  async collection (data) {
    throw new Error('A Serializer must implement the method collection')
  }

  /**
   * Serialize a single item of data
   * You must implement this method in your Serializer
   *
   * @param {*} data
   */
  async item (data) {
    throw new Error('A Serializer must implement the method item')
  }

  /**
   * Serialize a null value
   * You must implement this method in your Serializer
   */
  async null () {
    throw new Error('A Serializer must implement the method null')
  }

  /**
   * Serialize a metadata object
   * You must implement this method in your Serializer
   */
  async meta (meta) {
    throw new Error('A Serializer must implement the method meta')
  }

  /**
   * Serialize a pagination object
   * You must implement this method in your Serializer
   */
  async paginator (meta) {
    throw new Error('A Serializer must implement the method paginator')
  }

  /**
   * Merge included data with the main data for the resource.
   * Both includes and data have passed through either the
   * 'item' or 'collection' method of this serializer.
   *
   * @param {Object} data
   * @param {Object} includes
   */
  async mergeIncludes (data, includes) {
    // Include the includes data first.
    // If there is data with the same key as an include, data will take precedence.
    return Object.assign(includes, data)
  }
}

module.exports = SerializerAbstract


<|start_filename|>test/providers.spec.js<|end_filename|>
'use strict'

/**
 * adonis-bumblebee
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

const test = require('japa')
const { ioc } = require('@adonisjs/fold')

const setup = require('./setup')

test.group('Providers', group => {
  group.before(async () => {
    await setup()
  })

  group.beforeEach(() => {
    ioc.restore()
  })

  test('BumblebeeProvider', async assert => {
    assert.isDefined(ioc.use('Adonis/Addons/Bumblebee'))
    assert.isFalse(ioc._bindings['Adonis/Addons/Bumblebee'].singleton)
  })

  test('CommandsProvider', async assert => {
    assert.isDefined(ioc.use('Adonis/Commands/Make:Transformer'))
    assert.isFalse(ioc._bindings['Adonis/Commands/Make:Transformer'].singleton)
  })
})


<|start_filename|>providers/CommandsProvider.js<|end_filename|>
'use strict'

/**
 * adonis-bumblebee
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

const { ServiceProvider } = require('@adonisjs/fold')

class CommandsProvider extends ServiceProvider {
  /**
   * Register command bindings
   *
   * @method register
   *
   * @return {void}
   */
  register () {
    this.app.bind('Adonis/Commands/Make:Transformer', () => require('../src/Commands/MakeTransformer'))
  }

  /**
   * Add commands to Ace
   *
   * @method boot
   *
   * @return {void}
   */
  boot () {
    const ace = require('@adonisjs/ace')
    ace.addCommand('Adonis/Commands/Make:Transformer')
  }
}

module.exports = CommandsProvider
