- Application
Application
- containment
- Controller
Controller
- Loader
Loader
- Model
Model
- ModelManager
ModelManager
- Route
Route
- RouteSegment
RouteSegment
- Router
Router
- listen(port) ⇒
Promise.<void> Starts the server
- runProjectInitializers() ⇒
Promise.<void> Runs all consumer initializers
- start(port) ⇒
Promise.<undefined, Error> starts listening on the defined port
- getOwner(child) ⇒
Object Get the owner of an object
- setOwner(child, parent)
Set the owner object of the child object
- getModelName(model) ⇒
String Returns the name of the model that is associated with this controller. If options.model is passed to controller it will take precedence, otherwise the controller will attempt to lookup a model matching the controller's name
- get(name) ⇒
Object Returns the loaded module object by name
- define(DataTypes)
Model definition
- addModel(Model)
Adds a model to internal cache
class FooModel extends parch.Model { constructor(options) { super(options); }associate(Foo, models) { }
define(DataTypes) { } }
modelManager.addModel(Model);- inject(context, lookup, propertyName) ⇒
Object Inject an object into another object
- lookup(name) ⇒
Object Find an object in the registry. If the object isn't found in the registry, lookup will attempt to find it by requiring it in. If the require fails the lookup fails
- register(name, Obj, options) ⇒
Object Register an object in the registry by name. If the name exists and it was registered with the { singleton: true } option, an error will be thrown.
- hasLeadingSlash() ⇒
Boolean Determines if a path segment contains a leading slash /
- hasTrailingSlash() ⇒
Boolean Determines if a path segment contains a trailing slash /
- _buildSegment() ⇒
String Builds a consistent path segment, regardless of slashes
- namespace(namespace, routes)
Bind a set of routes to a namespace. Uses {{#crossLink "Router/_buildRoute:method"}}_buildRoute{{/crossLink}} to normalize the path
- resource(name, options)
Register a resource and wire up restful endpoints. Uses {{#crossLink "Router/_buildRoute:method"}}_buildRoute{{/crossLink}} to normalize the path and builds your 5 basic CRUD endpoints
- route(path, options)
Register a single route. Uses {{#crossLink "Router/_buildRoute:method"}}_buildRoute{{/crossLink}} to normalize the path
- createRecord(name) ⇒
Object Creates a record
- findAll(name) ⇒
Array|Object Returns all records. Passing an optional query will query those records.
- findOne(name) ⇒
Array|Object Returns a single record by id
- queryRecord(name) ⇒
Object Returns the first record matching the passed query
- updateRecord(name) ⇒
Object Updates a record by id
Application
Kind: global class
- Application
- new Application(options)
- .app :
Object - .projectDirectory :
String
| Param | Type | Description |
|---|---|---|
| options | Object |
Application config options See configuration |
Restify application instance
Kind: instance property of Application
Properties
| Name |
|---|
| app |
The consuming project's directory
Kind: instance property of Application
Properties
| Name |
|---|
| projectDirectory |
Controller
Kind: global class
Todo
- add default restfull methods (index, show, etc)
- Controller
- new Controller(registry, options)
- .errors :
Object - .models :
Array - .modelName :
String - .modelNameLookup :
String - .STATUS_CODES :
Object
| Param | Type | Description |
|---|---|---|
| registry | Object |
module registry |
| options | Object |
configuration options |
| options.model | String |
override the default model name |
Restify errors map restify-errors
Kind: instance property of Controller
Properties
| Name |
|---|
| errors |
Object containing all models registered
Kind: instance property of Controller
Properties
| Name |
|---|
| models |
The name of the model that belongs to this controller. If one cannot be found this will be undefined
Kind: instance property of Controller
Properties
| Name |
|---|
| modelName |
Pluralized version of modelName
Kind: instance property of Controller
Properties
| Name |
|---|
| modelNameLookup |
An object mapping of status codes and their corresponding value
Kind: instance property of Controller
Properties
| Name |
|---|
| STATUS_CODES |
Loader
Kind: global class
- Loader
- new Loader(settings)
- .type :
String - .filter :
String - .loadPath :
String
| Param | Type | Description |
|---|---|---|
| settings | Object |
|
| settings.type | String |
the loader type (controller, model, etc) |
| settings.filter | RegExp |
loader filter |
| settings.path | String |
module loader path |
Loader type
Kind: instance property of Loader
Properties
| Name |
|---|
| type |
Loader filter
Kind: instance property of Loader
Properties
| Name |
|---|
| filter |
Module load path
Kind: instance property of Loader
Properties
| Name |
|---|
| loadPath |
Model
Kind: global class
- Model
- new Model(options)
- .options :
Object
| Param | Type | Description |
|---|---|---|
| options | Object |
sequelize model options Sequelize Configuration |
Model options get passed directly to sequelize model definition. The main difference is the separation of model constructor options and model attribute definitions.
see http://docs.sequelizejs.com/en/v3/docs/models-definition/Kind: instance property of Model
Properties
| Name |
|---|
| options |
ModelManager
Kind: global class
- ModelManager
- new ModelManager(settings)
- .Sequelize :
Object - .sequelize :
Object
| Param | Type |
|---|---|
| settings | Object |
| settings.connection | Object |
Sequelize class
Kind: instance property of ModelManager
Properties
| Name |
|---|
| Sequelize |
Sequelize instance
Kind: instance property of ModelManager
Properties
| Name |
|---|
| sequelize |
Route
Kind: global class
- Route
- new Route()
- .path :
String - .segments :
Array
Returns: Object - path object
| Param | Type |
|---|---|
| ...segment | String |
Example
new Route("foo", "/bar", "baz/");
/**
* {
* path: "/foo/bar/baz"
* segments: [
* {{#crossLink "RouteSegment"}}RouteSegment{{/crossLink}},
* {{#crossLink "RouteSegment"}}RouteSegment{{/crossLink}},
* {{#crossLink "RouteSegment"}}RouteSegment{{/crossLink}}
* ]
* }
*The path is the fully built path from segments e.g. /foo/bar/baz
Kind: instance property of Route
Properties
| Name |
|---|
| path |
All segments that make up this route. Consists of an array of {{#crossLink "RouteSegment"}}RouteSegments{{/crossLink}}
Kind: instance property of Route
Properties
| Name |
|---|
| segments |
RouteSegment
Kind: global class
- RouteSegment
- new RouteSegment(segment)
- .segment :
String - .path :
String
| Param | Type | Description |
|---|---|---|
| segment | String |
A single route segment |
Example
new RouteSegment("/foo"); => { path: "/foo", segment: "/foo" }
new RouteSegment("foo"); => { path: "/foo", segment: "foo" }
new RouteSegment("/foo/"); => { path: "/foo", segment: "/foo/" }
new RouteSegment("foo/"); => { path: "/foo", segment: "foo/" }Segment represents the original path segment that was passed in
Kind: instance property of RouteSegment
Properties
| Name |
|---|
| segment |
The normalized path segment after removing/adding slashes
Kind: instance property of RouteSegment
Properties
| Name |
|---|
| path |
Router
Kind: global class
- Router
- new Router(registry)
- instance
- .loader :
Object - .namespacePrefix :
String
- .loader :
- static
- .map(settings, callback) ⇒
undefined
- .map(settings, callback) ⇒
| Param | Type | Description |
|---|---|---|
| registry | Object |
{{#crossLink "Registry"}}module registry{{/crossLink}} |
Contains the model and controller {{#crossLink "Loader"}}loaders{{/crossLink}}
Kind: instance property of Router
Properties
| Name |
|---|
| loader |
An optional namespace to place before all routes (e.g. /v1)
Kind: instance property of Router
Properties
| Name |
|---|
| namespacePrefix |
configures router resources
Kind: static method of Router
| Param | Type | Description |
|---|---|---|
| settings | Object |
|
| callback | function |
called with the router instance |
Starts the server
Kind: global function
| Param | Type |
|---|---|
| port | Number |
Runs all consumer initializers
starts listening on the defined port
Kind: global function
| Param | Type | Description |
|---|---|---|
| port | Number |
the port to listen on. Default: 3000 |
Get the owner of an object
Kind: global function
Returns: Object - parent (owner)
| Param | Type | Description |
|---|---|---|
| child | Object |
object from which to fetch the parent |
Example
class UserController extends parch.Controller {
doStuff(req, res, next) {
const store = getOwner(this).lookup("service:store");
return store.findAll();
}
}Set the owner object of the child object
Kind: global function
| Param | Type | Description |
|---|---|---|
| child | Object |
child object |
| parent | Object |
parent (owner) object |
Example
setOwner({}, "service:store", "store");
{}.storeReturns the name of the model that is associated with this controller. If options.model is passed to controller it will take precedence, otherwise the controller will attempt to lookup a model matching the controller's name
Kind: global function
Returns: String - modelName
| Param | Type | Description |
|---|---|---|
| model | String |
name of the model to use |
Returns the loaded module object by name
Kind: global function
Returns: Object - module object
| Param | Type |
|---|---|
| name | String |
Model definition
Kind: global function
| Param | Type | Description |
|---|---|---|
| DataTypes | Object |
sequelize DataTypes Object See Sequelize DataTypes |
Example
define(DataTypes) {
const user = {
username: {
allowNull: false
type: DataTypes.STRING
}
};
return user;
}Adds a model to internal cache
class FooModel extends parch.Model {
constructor(options) {
super(options);
}
associate(Foo, models) {
}
define(DataTypes) {
}
}
modelManager.addModel(Model);
Kind: global function
| Param | Type | Description |
|---|---|---|
| Model | Object |
parch model class |
Inject an object into another object
Kind: global function
Returns: Object - context
| Param | Type | Description |
|---|---|---|
| context | Object |
the object to inject onto |
| lookup | String |
name by which to look search for the injection in the registry |
| propertyName | String |
optional property name of the newly injected object |
Example
registry.inject(object, "service:store");
// object.store
registry.inject(object, "service:model-manager", "modelManager");
// object.modelManagerFind an object in the registry. If the object isn't found in the registry, lookup will attempt to find it by requiring it in. If the require fails the lookup fails
Kind: global function
| Param | Type | Description |
|---|---|---|
| name | String |
colon delimited lookup string "service:foo" |
Example
registry.lookup("service:foo");Register an object in the registry by name. If the name exists and it was registered with the { singleton: true } option, an error will be thrown.
Kind: global function
Returns: Object - Obj
| Param | Type | Description |
|---|---|---|
| name | String |
the name by which to register the object |
| Obj | Object |
the object to store in the registry |
| options | Object |
register options |
| options.instantiate | Boolean |
instantiate the object when registering it |
| options.singleton | Boolean |
only allow one registration of this name/object |
Example
registry.register("service:foo", { foo: "bar" });Determines if a path segment contains a leading slash /
Kind: global function
Example
new RouteSegment("foo").hasLeadingSlash(); => false
new RouteSegment("foo/").hasLeadingSlash(); => false
new RouteSegment("/foo/").hasLeadingSlash(); => true
new RouteSegment("/foo").hasLeadingSlash(); => trueDetermines if a path segment contains a trailing slash /
Kind: global function
Example
new RouteSegment("foo").hasTrailingSlash(); => false
new RouteSegment("/foo").hasTrailingSlash(); => false
new RouteSegment("/foo/").hasTrailingSlash(); => true
new RouteSegment("foo/").hasTrailingSlash(); => trueBuilds a consistent path segment, regardless of slashes
Kind: global function
Returns: String - path segment
Bind a set of routes to a namespace. Uses {{#crossLink "Router/_buildRoute:method"}}_buildRoute{{/crossLink}} to normalize the path
Kind: global function
Since: 0.9.0
| Param | Type | Description |
|---|---|---|
| namespace | String |
the namespace to bind to, with or without leading slash |
| routes | Array.<Object> |
array of routes to bind to the namespace |
Example
Router.map(function () {
this.namespace("/users/:userId", [
{ path: "/setProfileImage", using: "user:setImage", method: "post" }
])
});Register a resource and wire up restful endpoints. Uses {{#crossLink "Router/_buildRoute:method"}}_buildRoute{{/crossLink}} to normalize the path and builds your 5 basic CRUD endpoints
Kind: global function
| Param | Type | Description |
|---|---|---|
| name | String |
the resource name in singular form |
| options | Object |
resource mapping options |
| options.namespace | String |
mount the resource endpoint under a namespace |
Example
Router.map(function () {
this.resource("user");
// Optionally prefix this resource with a namespace
this.resource("user", { namespace: "api" })
});Register a single route. Uses {{#crossLink "Router/_buildRoute:method"}}_buildRoute{{/crossLink}} to normalize the path
Kind: global function
| Param | Type | Description |
|---|---|---|
| path | String |
the route path (e.g. /foo/bar) |
| options | Object |
|
| options.using | String |
colon delimited controller method identifier |
| options.method | String |
http method |
Example
Router.map(function () {
this.route("/user/foo", { using: "users:foo", method: "get" });
});Creates a record
Kind: global function
Returns: Object - seralized record instance
| Param |
|---|
| name |
Example
return store.createRecord("user", {
firstName: "hank",
lastName: "hill"
});Returns all records. Passing an optional query will query those records.
Kind: global function
Returns: Array | Object - serialized record arry
| Param |
|---|
| name |
Example
return store.findAll("user");
return store.findAll("user", {
firstName: "Jon"
})Returns a single record by id
Kind: global function
Returns: Array | Object - serialized record array
| Param |
|---|
| name |
Example
return store.findOne("user", 1);Returns the first record matching the passed query
Kind: global function
Returns: Object - serialized record instance
| Param |
|---|
| name |
Example
return store.queryRecord("user", {
firstName: "jon"
})Updates a record by id
Kind: global function
Returns: Object - seralized record instance
| Param |
|---|
| name |
Example
return store.updateRecord("user", 1, { firstName: "Jane" });