Refactor various naming conventions.
This commit is contained in:
parent
d931019269
commit
b9a239db32
|
@ -3,6 +3,6 @@ var app = asteroid();
|
|||
|
||||
app.use(asteroid.configure());
|
||||
app.use(asteroid.bodyParser());
|
||||
app.use(asteroid.resources());
|
||||
app.use(asteroid.routes());
|
||||
|
||||
app.listen(3000);
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"production": {
|
||||
"dependencies": {
|
||||
"connection": "oracle"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"module": "store"
|
||||
"module": "data-source"
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"module": "collection",
|
||||
"module": "model-route",
|
||||
"options": {
|
||||
"path": "/todos"
|
||||
},
|
||||
|
|
|
@ -17,6 +17,6 @@
|
|||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"store": "db"
|
||||
"data-source": "db"
|
||||
}
|
||||
}
|
|
@ -8,20 +8,20 @@ var asteroid = require('../asteroid');
|
|||
* Export the middleware.
|
||||
*/
|
||||
|
||||
module.exports = resources;
|
||||
module.exports = routes;
|
||||
|
||||
/**
|
||||
* Build a temp app for mounting resources.
|
||||
*/
|
||||
|
||||
function resources() {
|
||||
function routes() {
|
||||
return function (req, res, next) {
|
||||
// xxx - cache the temp app and only build when modules change?
|
||||
var tempApp = asteroid();
|
||||
var resources = req.modules.instanceOf('Resource');
|
||||
var routes = req.modules.instanceOf('Route');
|
||||
|
||||
// mount all resources
|
||||
resources.forEach(function (r) {
|
||||
routes.forEach(function (r) {
|
||||
r.mount(tempApp);
|
||||
});
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
/**
|
||||
* A generated `Collection` example...
|
||||
*
|
||||
* Examples should show a working module api
|
||||
* and be used in tests to continously check
|
||||
* they function as expected.
|
||||
*/
|
||||
|
||||
var Collection = require('../');
|
||||
var collection = Collection.create();
|
||||
|
||||
collection.myMethod();
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* collection ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/collection');
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"name": "collection",
|
||||
"description": "collection",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "latest",
|
||||
"jugglingdb": "~0.2.0-29"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "latest"
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
var Collection = require('../');
|
||||
|
||||
describe('Collection', function(){
|
||||
var collection;
|
||||
|
||||
beforeEach(function(){
|
||||
collection = new Collection;
|
||||
});
|
||||
|
||||
describe('.myMethod', function(){
|
||||
// example sync test
|
||||
it('should <description of behavior>', function() {
|
||||
collection.myMethod();
|
||||
});
|
||||
|
||||
// example async test
|
||||
it('should <description of behavior>', function(done) {
|
||||
setTimeout(function () {
|
||||
collection.myMethod();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* collection test setup and support.
|
||||
*/
|
||||
|
||||
assert = require('assert');
|
|
@ -1,12 +0,0 @@
|
|||
/**
|
||||
* A generated `Connection` example...
|
||||
*
|
||||
* Examples should show a working module api
|
||||
* and be used in tests to continously check
|
||||
* they function as expected.
|
||||
*/
|
||||
|
||||
var Connection = require('../');
|
||||
var connection = Connection.create();
|
||||
|
||||
connection.myMethod();
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* connection ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/connection');
|
|
@ -1,50 +0,0 @@
|
|||
/**
|
||||
* Expose `Connection`.
|
||||
*/
|
||||
|
||||
module.exports = Connection;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var AsteroidModule = require('asteroid-module')
|
||||
, debug = require('debug')('connection')
|
||||
, util = require('util')
|
||||
, inherits = util.inherits
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Create a new `Connection` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Connection}
|
||||
*/
|
||||
|
||||
function Connection(options) {
|
||||
AsteroidModule.apply(this, arguments);
|
||||
this.options = options;
|
||||
|
||||
// inheriting connections must provide an adapter
|
||||
// otherwise throw when this connection's adapter
|
||||
// is used...
|
||||
this.adapter = function () {
|
||||
throw new Error('connection has not provided an adapter!');
|
||||
}
|
||||
|
||||
debug('created with options', options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `AsteroidModule`.
|
||||
*/
|
||||
|
||||
inherits(Connection, AsteroidModule);
|
||||
|
||||
/**
|
||||
* Connection Options
|
||||
*/
|
||||
|
||||
Connection.options = {
|
||||
"adapter": {type: "string"}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
var Connection = require('../');
|
||||
|
||||
describe('Connection', function(){
|
||||
var connection;
|
||||
|
||||
beforeEach(function(){
|
||||
connection = new Connection;
|
||||
});
|
||||
|
||||
describe('.myMethod', function(){
|
||||
// example sync test
|
||||
it('should <description of behavior>', function() {
|
||||
connection.myMethod();
|
||||
});
|
||||
|
||||
// example async test
|
||||
it('should <description of behavior>', function(done) {
|
||||
setTimeout(function () {
|
||||
connection.myMethod();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
# connection
|
||||
# data-source
|
||||
|
||||
## About
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* connection ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/data-source');
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* Expose `DataSource`.
|
||||
*/
|
||||
|
||||
module.exports = DataSource;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var AsteroidModule = require('asteroid-module')
|
||||
, Schema = require('jugglingdb').Schema
|
||||
, debug = require('debug')('connection')
|
||||
, util = require('util')
|
||||
, inherits = util.inherits
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Create a new `DataSource` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {DataSource}
|
||||
*/
|
||||
|
||||
function DataSource(options) {
|
||||
AsteroidModule.apply(this, arguments);
|
||||
this.options = options;
|
||||
|
||||
// construct a schema with the available adapter
|
||||
// or use the default in memory adapter
|
||||
this.schema = new Schema(this.adapter || require('./memory'), options);
|
||||
|
||||
debug('created with options', options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `AsteroidModule`.
|
||||
*/
|
||||
|
||||
inherits(DataSource, AsteroidModule);
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "connection",
|
||||
"description": "connection",
|
||||
"name": "data-source",
|
||||
"description": "data-source",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"test": "mocha"
|
|
@ -1,22 +1,22 @@
|
|||
var Connection = require('../');
|
||||
var DataSource = require('../');
|
||||
|
||||
describe('Connection', function(){
|
||||
describe('DataSource', function(){
|
||||
var connection;
|
||||
|
||||
beforeEach(function(){
|
||||
connection = new Connection;
|
||||
dataSource = new DataSource;
|
||||
});
|
||||
|
||||
describe('.myMethod', function(){
|
||||
// example sync test
|
||||
it('should <description of behavior>', function() {
|
||||
connection.myMethod();
|
||||
dataSource.myMethod();
|
||||
});
|
||||
|
||||
// example async test
|
||||
it('should <description of behavior>', function(done) {
|
||||
setTimeout(function () {
|
||||
connection.myMethod();
|
||||
dataSource.myMethod();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
0
node_modules/connection/test/support.js → node_modules/data-source/test/support.js
generated
vendored
0
node_modules/connection/test/support.js → node_modules/data-source/test/support.js
generated
vendored
|
@ -1,12 +1,12 @@
|
|||
# collection
|
||||
# model route
|
||||
|
||||
## About
|
||||
|
||||
A `Collection` inherits from the [resource](../resource) class. It provides HTTP access to a supplied [model](../model) instance.
|
||||
A `ModelRoute` inherits from the [route](../route) class. It provides HTTP access to a supplied [model](../model) instance.
|
||||
|
||||
## Config
|
||||
|
||||
Supports all configuration of a [resource](../resource).
|
||||
Supports all configuration of a [resource](../route).
|
||||
|
||||
### Options
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* collection ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/model-route');
|
22
node_modules/collection/lib/collection.js → node_modules/model-route/lib/model-route.js
generated
vendored
22
node_modules/collection/lib/collection.js → node_modules/model-route/lib/model-route.js
generated
vendored
|
@ -1,28 +1,28 @@
|
|||
/**
|
||||
* Expose `Collection`.
|
||||
* Expose `ModelRoute`.
|
||||
*/
|
||||
|
||||
module.exports = Collection;
|
||||
module.exports = ModelRoute;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Resource = require('resource')
|
||||
var Route = require('route')
|
||||
, debug = require('debug')('collection')
|
||||
, util = require('util')
|
||||
, inherits = util.inherits
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Create a new `Collection` with the given `options`.
|
||||
* Create a new `ModelRoute` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Collection}
|
||||
* @return {ModelRoute}
|
||||
*/
|
||||
|
||||
function Collection(options) {
|
||||
Resource.apply(this, arguments);
|
||||
function ModelRoute(options) {
|
||||
Route.apply(this, arguments);
|
||||
|
||||
this.options = options;
|
||||
|
||||
|
@ -36,20 +36,20 @@ function Collection(options) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Resource`.
|
||||
* Inherit from `Route`.
|
||||
*/
|
||||
|
||||
inherits(Collection, Resource);
|
||||
inherits(ModelRoute, Route);
|
||||
|
||||
/**
|
||||
* Dependencies.
|
||||
*/
|
||||
|
||||
Collection.dependencies = {
|
||||
ModelRoute.dependencies = {
|
||||
'model': 'model'
|
||||
}
|
||||
|
||||
Collection.prototype.setupRoutes = function (app) {
|
||||
ModelRoute.prototype.setupRoutes = function (app) {
|
||||
var Model = this.model;
|
||||
var ctx;
|
||||
var collection = this;
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"name": "store",
|
||||
"description": "store",
|
||||
"name": "model-route",
|
||||
"description": "model-route",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -11,4 +11,4 @@
|
|||
"devDependencies": {
|
||||
"mocha": "latest"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ An array of properties describing the model's schema.
|
|||
"properties": [
|
||||
{
|
||||
"name": "title",
|
||||
"type": "string"
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "done",
|
||||
|
@ -32,6 +32,6 @@ An array of properties describing the model's schema.
|
|||
|
||||
### Dependencies
|
||||
|
||||
#### store
|
||||
#### data source
|
||||
|
||||
A [store](../store) module instance.
|
||||
A [data-source](../data-source) for persisting data.
|
|
@ -32,8 +32,8 @@ function Model(options) {
|
|||
debug('created with options', options);
|
||||
|
||||
var dependencies = this.dependencies;
|
||||
var store = dependencies.store;
|
||||
var schema = this.schema = store.schema;
|
||||
var dataSource = dependencies['data-source'];
|
||||
var schema = this.schema = dataSource.schema;
|
||||
|
||||
assert(Array.isArray(options.properties), 'the ' + options._name + ' model requires an options.properties array');
|
||||
|
||||
|
@ -52,7 +52,7 @@ inherits(Model, AsteroidModule);
|
|||
*/
|
||||
|
||||
Model.dependencies = {
|
||||
'store': 'store'
|
||||
'data-source': 'data-source'
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
/**
|
||||
* A generated `Connection` example...
|
||||
*
|
||||
* Examples should show a working module api
|
||||
* and be used in tests to continously check
|
||||
* they function as expected.
|
||||
*/
|
||||
|
||||
var Connection = require('../');
|
||||
var connection = Connection.create();
|
||||
|
||||
connection.myMethod();
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* connection ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/oracle-connection');
|
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Expose `OracleConnection`.
|
||||
*/
|
||||
|
||||
module.exports = OracleConnection;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Connection = require('connection')
|
||||
, debug = require('debug')('oracle-connection')
|
||||
, util = require('util')
|
||||
, inherits = util.inherits
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Create a new `OracleConnection` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Connection}
|
||||
*/
|
||||
|
||||
function OracleConnection(options) {
|
||||
Connection.apply(this, arguments);
|
||||
this.options = options;
|
||||
|
||||
debug('created with options', options);
|
||||
|
||||
// provide the oracle jugglingdb adapter
|
||||
this.adapter = require('jugglingdb-oracle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `AsteroidModule`.
|
||||
*/
|
||||
|
||||
inherits(OracleConnection, Connection);
|
||||
|
||||
/**
|
||||
* Define options.
|
||||
*/
|
||||
|
||||
OracleConnection.options = {
|
||||
'host': {type: 'string', required: true},
|
||||
'port': {type: 'number', min: 10, max: 99999},
|
||||
'username': {type: 'string'},
|
||||
'password': {type: 'string'}
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* connection test setup and support.
|
||||
*/
|
||||
|
||||
assert = require('assert');
|
2
node_modules/oracle-connection/README.md → node_modules/oracle-data-source/README.md
generated
vendored
2
node_modules/oracle-connection/README.md → node_modules/oracle-data-source/README.md
generated
vendored
|
@ -1,4 +1,4 @@
|
|||
# orace-connection
|
||||
# oracle-data-source
|
||||
|
||||
## About
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* connection ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/oracle-data-source');
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Expose `OracleDataSource`.
|
||||
*/
|
||||
|
||||
module.exports = OracleDataSource;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var DataSource = require('data-source')
|
||||
, debug = require('debug')('oracle-data-source')
|
||||
, util = require('util')
|
||||
, inherits = util.inherits
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Create a new `OracleDataSource` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {DataSource}
|
||||
*/
|
||||
|
||||
function OracleDataSource(options) {
|
||||
DataSource.apply(this, arguments);
|
||||
debug('created with options', options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `AsteroidModule`.
|
||||
*/
|
||||
|
||||
inherits(OracleDataSource, DataSource);
|
||||
|
||||
/**
|
||||
* Define options.
|
||||
*/
|
||||
|
||||
OracleDataSource.options = {
|
||||
'database': {type: 'string', required: true},
|
||||
'host': {type: 'string', required: true},
|
||||
'port': {type: 'number', min: 10, max: 99999},
|
||||
'username': {type: 'string'},
|
||||
'password': {type: 'string'}
|
||||
};
|
||||
|
||||
/**
|
||||
* Provide the oracle jugglingdb adapter
|
||||
*/
|
||||
|
||||
OracleDataSource.prototype.adapter = require('jugglingdb-oracle');
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oracle-connection",
|
||||
"description": "connection",
|
||||
"name": "oracle-data-source",
|
||||
"description": "oracle-data-source",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"test": "mocha"
|
|
@ -1,73 +0,0 @@
|
|||
# asteroid.Resource
|
||||
|
||||
## About
|
||||
|
||||
A `Resource` inherits from the [asteroid module](../asteroid-module) class. It wraps an asteroid application so that it can be used as a sub application initialized by a configuration file.
|
||||
|
||||
This example shows the basic usage of a `Resource` as a sub application. You should never have to write this code since the resource will be created and mounted for you by asteroid.
|
||||
|
||||
var asteroid = require('asteroid');
|
||||
var Resource = require('resource');
|
||||
|
||||
var app = asteroid();
|
||||
var subApp = new Resource({root: '/my-sub-app'});
|
||||
subApp.mount(app);
|
||||
|
||||
subApp.get('/', function (req, res) {
|
||||
res.send(req.url); // /my-sub-app
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
|
||||
## resource.app
|
||||
|
||||
Each resource is constructed with a asteroid/express sub app at the path provided in the resource's `config.json` options.
|
||||
|
||||
### myResource.app.VERB(path, [callback...], callback)
|
||||
|
||||
The `myResource.VERB()` methods provide routing functionality inherited from [Express](http://expressjs.com/api.html#app.get), where **VERB** is one of the HTTP verbs, such as `myResource.post()`. See the [Express docs](http://expressjs.com/api.html#app.get) for more info.
|
||||
|
||||
|
||||
**Examples**
|
||||
|
||||
myResource.get('/hello-world', function(req, res) {
|
||||
res.send('hello world');
|
||||
});
|
||||
|
||||
|
||||
### myResource.app.use([path], middleware)
|
||||
|
||||
Use the given middleware function.
|
||||
|
||||
**Examples**
|
||||
|
||||
// a logger middleware
|
||||
myResource.use(function(req, res, next){
|
||||
console.log(req.method, req.url); // GET /my-resource
|
||||
next();
|
||||
});
|
||||
|
||||
## Config
|
||||
|
||||
### Options
|
||||
|
||||
#### path
|
||||
|
||||
The `asteroid.Route` path where the resource will be mounted.
|
||||
|
||||
**Examples**
|
||||
|
||||
{
|
||||
"options": {
|
||||
"path": "/foo" // responds at /foo
|
||||
}
|
||||
}
|
||||
|
||||
<!-- ... -->
|
||||
|
||||
{
|
||||
"options": {
|
||||
"path": "/foo/:bar" // provides :bar param at `req.param('bar')`.
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
/**
|
||||
* A generated `Resource` example...
|
||||
*
|
||||
* Examples should show a working module api
|
||||
* and be used in tests to continously check
|
||||
* they function as expected.
|
||||
*/
|
||||
|
||||
var Resource = require('../');
|
||||
var resource = Resource.create();
|
||||
|
||||
resource.myMethod();
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* resource ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/resource');
|
|
@ -1,24 +0,0 @@
|
|||
var Resource = require('../');
|
||||
|
||||
describe('Resource', function(){
|
||||
var resource;
|
||||
|
||||
beforeEach(function(){
|
||||
resource = new Resource;
|
||||
});
|
||||
|
||||
describe('.myMethod', function(){
|
||||
// example sync test
|
||||
it('should <description of behavior>', function() {
|
||||
resource.myMethod();
|
||||
});
|
||||
|
||||
// example async test
|
||||
it('should <description of behavior>', function(done) {
|
||||
setTimeout(function () {
|
||||
resource.myMethod();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,73 @@
|
|||
# asteroid.Route
|
||||
|
||||
## About
|
||||
|
||||
A `Route` inherits from the [asteroid module](../asteroid-module) class. It wraps an asteroid application so that it can be used as a sub application initialized by a configuration file.
|
||||
|
||||
This example shows the basic usage of a `Route` as a sub application. You should never have to write this code since the route will be created and mounted for you by asteroid.
|
||||
|
||||
var asteroid = require('asteroid');
|
||||
var Route = require('route');
|
||||
|
||||
var app = asteroid();
|
||||
var subApp = new Route({root: '/my-sub-app'});
|
||||
subApp.mount(app);
|
||||
|
||||
subApp.get('/', function (req, res) {
|
||||
res.send(req.url); // /my-sub-app
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
|
||||
## route.app
|
||||
|
||||
Each route is constructed with a asteroid/express sub app at the path provided in the route's `config.json` options.
|
||||
|
||||
### myRoute.app.VERB(path, [callback...], callback)
|
||||
|
||||
The `myRoute.VERB()` methods provide routing functionality inherited from [Express](http://expressjs.com/api.html#app.get), where **VERB** is one of the HTTP verbs, such as `myRoute.post()`. See the [Express docs](http://expressjs.com/api.html#app.get) for more info.
|
||||
|
||||
|
||||
**Examples**
|
||||
|
||||
myRoute.get('/hello-world', function(req, res) {
|
||||
res.send('hello world');
|
||||
});
|
||||
|
||||
|
||||
### myRoute.app.use([path], middleware)
|
||||
|
||||
Use the given middleware function.
|
||||
|
||||
**Examples**
|
||||
|
||||
// a logger middleware
|
||||
myRoute.use(function(req, res, next){
|
||||
console.log(req.method, req.url); // GET /my-route
|
||||
next();
|
||||
});
|
||||
|
||||
## Config
|
||||
|
||||
### Options
|
||||
|
||||
#### path
|
||||
|
||||
The `asteroid.Route` path where the route will be mounted.
|
||||
|
||||
**Examples**
|
||||
|
||||
{
|
||||
"options": {
|
||||
"path": "/foo" // responds at /foo
|
||||
}
|
||||
}
|
||||
|
||||
<!-- ... -->
|
||||
|
||||
{
|
||||
"options": {
|
||||
"path": "/foo/:bar" // provides :bar param at `req.param('bar')`.
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* resource ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/route');
|
0
node_modules/resource/lib/http-context.js → node_modules/route/lib/http-context.js
generated
vendored
0
node_modules/resource/lib/http-context.js → node_modules/route/lib/http-context.js
generated
vendored
|
@ -1,8 +1,8 @@
|
|||
/**
|
||||
* Expose `Resource`.
|
||||
* Expose `Route`.
|
||||
*/
|
||||
|
||||
module.exports = Resource;
|
||||
module.exports = Route;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
|
@ -17,18 +17,18 @@ var asteroid = require('asteroid')
|
|||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Create a new `Resource` with the given `options`.
|
||||
* Create a new `Route` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Resource}
|
||||
* @return {Route}
|
||||
*/
|
||||
|
||||
function Resource(options) {
|
||||
function Route(options) {
|
||||
AsteroidModule.apply(this, arguments);
|
||||
|
||||
// throw an error if args are not supplied
|
||||
assert(typeof options === 'object', 'Resource requires an options object');
|
||||
assert(options.path, 'Resource requires a path');
|
||||
assert(typeof options === 'object', 'Route requires an options object');
|
||||
assert(options.path, 'Route requires a path');
|
||||
|
||||
// create the sub app
|
||||
var app = this.app = asteroid();
|
||||
|
@ -46,13 +46,13 @@ function Resource(options) {
|
|||
* Inherit from `AsteroidModule`.
|
||||
*/
|
||||
|
||||
inherits(Resource, AsteroidModule);
|
||||
inherits(Route, AsteroidModule);
|
||||
|
||||
/**
|
||||
* Mount the sub app on the given parent app at the configured path.
|
||||
*/
|
||||
|
||||
Resource.prototype.mount = function (parent) {
|
||||
Route.prototype.mount = function (parent) {
|
||||
this.parent = parent;
|
||||
parent.use(this.options.path, this.app);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ Resource.prototype.mount = function (parent) {
|
|||
* Create an http context bound to the current resource.
|
||||
*/
|
||||
|
||||
Resource.prototype.createContext = function (req, res, next) {
|
||||
Route.prototype.createContext = function (req, res, next) {
|
||||
return new HttpContext(this, req, res, next);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ Resource.prototype.createContext = function (req, res, next) {
|
|||
* Override `on` to determine how many arguments an event handler expects.
|
||||
*/
|
||||
|
||||
Resource.prototype.on = function () {
|
||||
Route.prototype.on = function () {
|
||||
var fn = arguments[arguments.length - 1];
|
||||
|
||||
if(typeof fn === 'function') {
|
|
@ -1,10 +0,0 @@
|
|||
.DS_Store
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.swp
|
||||
*.swo
|
||||
node_modules/
|
|
@ -1,15 +0,0 @@
|
|||
# store
|
||||
|
||||
## About
|
||||
|
||||
Provides an in memory data store. The backing persistence can be swapped out by providing a connection.
|
||||
|
||||
### Options
|
||||
|
||||
tbd
|
||||
|
||||
### Dependencies
|
||||
|
||||
#### connection (optional)
|
||||
|
||||
By default data will be persisted in memory. You can swap out the persistence layer by providing a connection.
|
|
@ -1,12 +0,0 @@
|
|||
/**
|
||||
* A generated `Store` example...
|
||||
*
|
||||
* Examples should show a working module api
|
||||
* and be used in tests to continously check
|
||||
* they function as expected.
|
||||
*/
|
||||
|
||||
var Store = require('../');
|
||||
var store = Store.create();
|
||||
|
||||
store.myMethod();
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* store ~ public api
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/store');
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* Expose `Store`.
|
||||
*/
|
||||
|
||||
module.exports = Store;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var AsteroidModule = require('asteroid-module')
|
||||
, Schema = require('jugglingdb').Schema
|
||||
, debug = require('debug')('store')
|
||||
, util = require('util')
|
||||
, inherits = util.inherits
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Create a new `Store` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Store}
|
||||
*/
|
||||
|
||||
function Store(options) {
|
||||
AsteroidModule.apply(this, arguments);
|
||||
|
||||
// throw an error if args are not supplied
|
||||
// assert(typeof options === 'object', 'Store requires an options object');
|
||||
|
||||
this.options = options;
|
||||
|
||||
debug('created with options', options);
|
||||
|
||||
var dependencies = this.dependencies;
|
||||
var connection = (dependencies && dependencies.connection) || {};
|
||||
var adapter = this.adapter = (connection && connection.adapter) || require('./memory');
|
||||
|
||||
// TODO determine how to
|
||||
|
||||
this.schema = new Schema(adapter, connection.options);
|
||||
}
|
||||
|
||||
inherits(Store, AsteroidModule);
|
||||
|
||||
/**
|
||||
* Dependencies
|
||||
*/
|
||||
|
||||
Store.dependencies = {
|
||||
"connection": {module: "connection", optional: true}
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
var Store = require('../');
|
||||
|
||||
describe('Store', function(){
|
||||
var store;
|
||||
|
||||
beforeEach(function(){
|
||||
store = new Store;
|
||||
});
|
||||
|
||||
describe('.myMethod', function(){
|
||||
// example sync test
|
||||
it('should <description of behavior>', function() {
|
||||
store.myMethod();
|
||||
});
|
||||
|
||||
// example async test
|
||||
it('should <description of behavior>', function(done) {
|
||||
setTimeout(function () {
|
||||
store.myMethod();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* store test setup and support.
|
||||
*/
|
||||
|
||||
assert = require('assert');
|
Loading…
Reference in New Issue