项目作者: fabrix-app

项目描述 :
Spool: Basic RESTful API interface
高级语言: TypeScript
项目地址: git://github.com/fabrix-app/spool-tapestries.git
创建时间: 2018-06-19T16:59:57Z
项目社区:https://github.com/fabrix-app/spool-tapestries

开源协议:Other

下载


spool-tapestries

Gitter
@fabrix/spool-tapestries"">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

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

Configure

  1. // config/main.ts
  2. export const main {
  3. spools: [
  4. // ... other spools
  5. require('@fabrix/spool-tapestries').TapestriesSpool
  6. ]
  7. }
  1. // config/tapestries.ts
  2. export const tapestries = {
  3. /**
  4. * Generate routes for controller handlers.
  5. * You can set controllers to true/false to enable/disable
  6. * automatic tapestries routes globaly
  7. */
  8. controllers: {
  9. /**
  10. * Default methods to accept for routes generated from controller handlers.
  11. */
  12. method: '*',
  13. /**
  14. * List of controllers to ignore; that is, do not generate tapestry routes
  15. * for them.
  16. */
  17. ignore: [ ]
  18. },
  19. /**
  20. * Generate conventional Create, Read, Update, and Delete (CRUD) routes for
  21. * each Model.
  22. */
  23. models: {
  24. options: {
  25. /**
  26. * The max number of objects to return by default. Can be overridden in
  27. * the request using the ?limit argument.
  28. */
  29. defaultLimit: 100,
  30. /**
  31. * Subscribe to changes on requested models via WebSocket
  32. * (support provided by spool-websocket)
  33. */
  34. watch: false,
  35. /**
  36. * Whether to populate all model associations by default (for "find")
  37. */
  38. populate: true
  39. },
  40. actions: {
  41. create: true,
  42. find: true,
  43. update: true,
  44. destroy: true,
  45. /**
  46. * Specify which "association" endpoints to activate.
  47. */
  48. createAssociation: true,
  49. findAssociation: true,
  50. updateAssociation: true,
  51. destroyAssociation: true
  52. }
  53. },
  54. /**
  55. * Prefix your tapestry route paths
  56. */
  57. prefix: '/api/v1'
  58. }

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.