Code Monkey home page Code Monkey logo

spool-tapestries's Introduction

spool-tapestries

Gitter NPM version Build Status Test Coverage Dependency Status Follow @fabrix-app on Twitter

Tapestries Spool. This spool provides the tapestry interface, which other spools such as spool-sequelize implement, as well as a suite of tests that Tapestry implementations should pass.

Fabrix Tapestries Diagram

What are Tapestries?

Tapestries automatically generate easy-to-use RESTful endpoints for your models.

Install

$ npm install @fabrix/spool-tapestries --save

Configure

// config/main.ts
export const main  {
  spools: [
    // ... other spools
    require('@fabrix/spool-tapestries').TapestriesSpool
  ]
}
// config/tapestries.ts
export const tapestries = {
  /**
   * Generate routes for controller handlers.
   * You can set controllers to true/false to enable/disable 
   * automatic tapestries routes globaly
   */
  controllers: {
               
     /**
      * Default methods to accept for routes generated from controller handlers.
      */
     method: '*',
  
     /**
      * List of controllers to ignore; that is, do not generate tapestry routes
      * for them.
      */
     ignore: [ ]
   },

  /**
   * Generate conventional Create, Read, Update, and Delete (CRUD) routes for
   * each Model.
   */
  models: {
    options: {

      /**
       * The max number of objects to return by default. Can be overridden in
       * the request using the ?limit argument.
       */
      defaultLimit: 100,

      /**
       * Subscribe to changes on requested models via WebSocket
       * (support provided by spool-websocket)
       */
      watch: false,

      /**
       * Whether to populate all model associations by default (for "find")
       */
      populate: true
    },

    actions: {
      create: true,
      find: true,
      update: true,
      destroy: true,

      /**
       * Specify which "association" endpoints to activate.
       */
      createAssociation: true,
      findAssociation: true,
      updateAssociation: true,
      destroyAssociation: true
    }
  },

  /**
   * Prefix your tapestry route paths
   */
  prefix: '/api/v1'
}

API

api.services.TapestryService

The purpose of TapestryService is to transform and forward queries to the datastore.

create (modelName, values, [options])

param required? description example
modelName Yes The name of the model to create (in api.models) User
values Yes An object containing the values of the record to create { username: 'admin' }
options No Datastore-specific options

find (modelName, criteria, [options])

param required? description example
modelName Yes The name of the model to search for (in api.models) User
criteria Yes An object containing the query criteria { username: 'admin' }
options No Datastore-specific options

update (modelName, criteria, values, [options])

param required? description example
modelName Yes The name of the model to create (in api.models) User
criteria Yes An object containing the query criteria { username: 'admin' }
values Yes An object containing the values to update { username: 'tjwebb' }
options No Datastore-specific options

destroy (modelName, criteria, options)

param required? description example
modelName Yes The name of the model to create (in api.models) User
criteria Yes An object containing the query criteria { username: 'admin' }
values Yes An object containing the values to update { username: 'tjwebb' }
options No Datastore-specific options

createAssociation (parentModelName, parentId, childAttributeName, values, [options])

param required? description example
parentModelName Yes The name of the parent model User
parentId Yes The id of the parent model 1
childAttributeName Yes The name of the attribute to create and associate with the parent roles
values Yes An object containing the values to create { name: 'adminRole' }
options No Datastore-specific options

findAssociation (parentModelName, parentId, childAttributeName, criteria, [options])

param required? description example
parentModelName Yes The name of the parent model User
parentId Yes The id of the parent model 1
childAttributeName Yes The name of the attribute to create and associate with the parent roles
criteria Yes An object containing the criteria to search on, or an id { name: 'adminRole' }
options No Datastore-specific options

updateAssociation (parentModelName, parentId, childAttributeName, criteria, values, [options])

param required? description example
parentModelName Yes The name of the parent model User
parentId Yes The id of the parent model 1
childAttributeName Yes The name of the attribute to create and associate with the parent roles
criteria Yes An object containing the criteria to search on, or an id { name: 'adminRole' }
values Yes An object containing the values to update { name: 'adminRole' }
options No Datastore-specific options

destroyAssociation (parentModelName, parentId, childAttributeName, criteria, [options])

param required? description example
parentModelName Yes The name of the parent model User
parentId Yes The id of the parent model 1
childAttributeName Yes The name of the attribute to destroy and dissociate from the parent roles
criteria Yes An object containing the criteria to search on, or an id { name: 'adminRole' }
options No Datastore-specific options

api.controllers.TapestryController

The purpose of the TapestryController is to transform and forward requests to the TapestryService.

spool-tapestries's People

Contributors

scott-wyatt avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.