1.6.0 • Published 5 years ago

@fabrix/spool-tapestries v1.6.0

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

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])

paramrequired?descriptionexample
modelNameYesThe name of the model to create (in api.models)User
valuesYesAn object containing the values of the record to create{ username: 'admin' }
optionsNoDatastore-specific options

find (modelName, criteria, [options])

paramrequired?descriptionexample
modelNameYesThe name of the model to search for (in api.models)User
criteriaYesAn object containing the query criteria{ username: 'admin' }
optionsNoDatastore-specific options

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

paramrequired?descriptionexample
modelNameYesThe name of the model to create (in api.models)User
criteriaYesAn object containing the query criteria{ username: 'admin' }
valuesYesAn object containing the values to update{ username: 'tjwebb' }
optionsNoDatastore-specific options

destroy (modelName, criteria, options)

paramrequired?descriptionexample
modelNameYesThe name of the model to create (in api.models)User
criteriaYesAn object containing the query criteria{ username: 'admin' }
valuesYesAn object containing the values to update{ username: 'tjwebb' }
optionsNoDatastore-specific options

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

paramrequired?descriptionexample
parentModelNameYesThe name of the parent modelUser
parentIdYesThe id of the parent model1
childAttributeNameYesThe name of the attribute to create and associate with the parentroles
valuesYesAn object containing the values to create{ name: 'adminRole' }
optionsNoDatastore-specific options

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

paramrequired?descriptionexample
parentModelNameYesThe name of the parent modelUser
parentIdYesThe id of the parent model1
childAttributeNameYesThe name of the attribute to create and associate with the parentroles
criteriaYesAn object containing the criteria to search on, or an id{ name: 'adminRole' }
optionsNoDatastore-specific options

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

paramrequired?descriptionexample
parentModelNameYesThe name of the parent modelUser
parentIdYesThe id of the parent model1
childAttributeNameYesThe name of the attribute to create and associate with the parentroles
criteriaYesAn object containing the criteria to search on, or an id{ name: 'adminRole' }
valuesYesAn object containing the values to update{ name: 'adminRole' }
optionsNoDatastore-specific options

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

paramrequired?descriptionexample
parentModelNameYesThe name of the parent modelUser
parentIdYesThe id of the parent model1
childAttributeNameYesThe name of the attribute to destroy and dissociate from the parentroles
criteriaYesAn object containing the criteria to search on, or an id{ name: 'adminRole' }
optionsNoDatastore-specific options

api.controllers.TapestryController

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

1.6.0

5 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-alpha.9

6 years ago

1.0.0-alpha.7

6 years ago

1.0.0-alpha.6

6 years ago

1.0.0-alpha.5

6 years ago

1.0.0-alpha.4

6 years ago