1.0.1 • Published 8 years ago

engine-composition-adapter v1.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

engine-composition-adapter Version Downloads

The base composition adapter class.

Use this module to create custom adapters for Engine composition.

Installation

$ npm i --save engine-composition-adapter

Example

"use strict";

// Include the CompositionAdapter class
const CompositionAdapter = require("engine-composition-adapter");

// Extend a custom adapter from CompositionAdapter
class MyCustomAdapter extends CompositionAdapter {
    // And implement the exists method
    exists (name, cb) {
        cb(null, true);
    }
}

// Create a new adapter instance
var crud = new MyCustomAdapter();

// Call the `exists` method
crud.exists("layout", (err, exists) => {
    console.log(err || exists);
    // => true

    // Call other method (which is not implemented)
    crud.list((err, instances) => {
        console.log(err || instances);
        // => {
        //  [Error: Method list not implement. Override the list method in your adapter to implement this.]
        //  code: 'METHOD_NOT_IMPLEMENTED'
        // }
    });
});

Documentation

exists(name, cb)

Checks if an instance exists.

Params

  • String name: The instance name.
  • Function cb: The callback function.

list(cb)

List the instances.

Params

  • Function cb: The callback function.

readAll(cb)

Read all the instances.

Params

  • Function cb: The callback function.

create(name, data, cb)

Creates a new instance.

Params

  • String name: The instance name.
  • Object data: The instance content.
  • Function cb: The callback function.

read(name, cb)

Reads the instance content.

Params

  • String name: The instance name.
  • Function cb: The callback function.

update(name, data, cb)

Updates the instance content.

Params

  • String name: The instance name.
  • Object data: The instance content.
  • Function cb: The callback function.

remove(name, cb)

Removes the instance.

Params

  • String name: The instance name.
  • Function cb: The callback function.

remove(oldName, newName, cb)

rename Renames the instance.

Params

  • String oldName: The old instance name.
  • String newName: The new instance name.
  • Function cb: The callback function.

upsert(name, data, cb)

Creates or updates the specified instance.

Params

  • String name: The instance name.
  • Object data: The instance content.
  • Function cb: The callback function.

readFile(path, cb)

Reads a file from app folder.

Params

  • String path: The file path (relative to the app directory).
  • Function cb: The callback function.

readFile(name, content, cb)

Writes a file from app folder.

Params

  • String name: The file path (relative to the app directory).
  • String content: The content to write in the file.
  • Function cb: The callback function.

How to contribute

Have an idea? Found a bug? See how to contribute.

Where is this library used?

If you are using this library in one of your projects, add it in this list. :sparkles:

License

MIT © jillix