diff --git a/.gitignore b/.gitignore index 6af74074..d975c43c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ + .DS_Store *.seed *.log @@ -6,5 +7,4 @@ *.out *.pid *.swp -*.swo -node_modules/ +*.swo \ No newline at end of file diff --git a/README.md b/README.md index 54e386f1..f5e6b06e 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,14 @@ v0.0.1 ## Install - slnode install asteroid + slnode install asteroid -g ## Example - var Asteroid = require('asteroid'); - var asteroid = Asteroid.create(); + var asteroid = require('asteroid'); + var app = asteroid(); - asteroid.myMethod(); \ No newline at end of file + app.use(asteroid.configure()); + app.use(asteroid.resources()); + + app.listen(3000); diff --git a/node_modules/.bin/express b/node_modules/.bin/express new file mode 120000 index 00000000..b741d99c --- /dev/null +++ b/node_modules/.bin/express @@ -0,0 +1 @@ +../express/bin/express \ No newline at end of file diff --git a/node_modules/asteroid-module/.gitignore b/node_modules/asteroid-module/.gitignore new file mode 100644 index 00000000..6af74074 --- /dev/null +++ b/node_modules/asteroid-module/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.swp +*.swo +node_modules/ diff --git a/node_modules/asteroid-module/README.md b/node_modules/asteroid-module/README.md new file mode 100644 index 00000000..c9830506 --- /dev/null +++ b/node_modules/asteroid-module/README.md @@ -0,0 +1,13 @@ +# asteroid-module +v0.0.1 + +## Install + + slnode install asteroid-module + +## Example + + var AsteroidModule = require('asteroid-module'); + var asteroidModule = AsteroidModule.create(); + + asteroidModule.myMethod(); \ No newline at end of file diff --git a/node_modules/asteroid-module/example/example.js b/node_modules/asteroid-module/example/example.js new file mode 100644 index 00000000..af757b28 --- /dev/null +++ b/node_modules/asteroid-module/example/example.js @@ -0,0 +1,12 @@ +/** + * A generated `AsteroidModule` example... + * + * Examples should show a working module api + * and be used in tests to continously check + * they function as expected. + */ + +var AsteroidModule = require('../'); +var asteroidModule = AsteroidModule.create(); + +asteroidModule.myMethod(); \ No newline at end of file diff --git a/node_modules/asteroid-module/index.js b/node_modules/asteroid-module/index.js new file mode 100644 index 00000000..abb2ce9d --- /dev/null +++ b/node_modules/asteroid-module/index.js @@ -0,0 +1,5 @@ +/** + * asteroid-module ~ public api + */ + +module.exports = require('./lib/asteroid-module'); \ No newline at end of file diff --git a/node_modules/asteroid-module/lib/asteroid-module.js b/node_modules/asteroid-module/lib/asteroid-module.js new file mode 100644 index 00000000..ea83f4aa --- /dev/null +++ b/node_modules/asteroid-module/lib/asteroid-module.js @@ -0,0 +1,39 @@ +/** + * Expose `AsteroidModule`. + */ + +module.exports = AsteroidModule; + +/** + * Module dependencies. + */ + +var Module = require('module-loader').Module + , debug = require('debug')('asteroid-module') + , util = require('util') + , inherits = util.inherits + , assert = require('assert'); + +/** + * Create a new `AsteroidModule` with the given `options`. + * + * @param {Object} options + * @return {AsteroidModule} + */ + +function AsteroidModule(options) { + Module.apply(this, arguments); + + // throw an error if args are not supplied + assert(typeof options === 'object', 'AsteroidModule requires an options object'); + + this.options = options; + + debug('created with options', options); +} + +/** + * Inherit from `Module`. + */ + +inherits(AsteroidModule, Module); \ No newline at end of file diff --git a/node_modules/asteroid-module/package.json b/node_modules/asteroid-module/package.json new file mode 100644 index 00000000..7a779309 --- /dev/null +++ b/node_modules/asteroid-module/package.json @@ -0,0 +1,14 @@ +{ + "name": "asteroid-module", + "description": "asteroid-module", + "version": "0.0.1", + "scripts": { + "test": "mocha" + }, + "dependencies": { + "debug": "latest" + }, + "devDependencies": { + "mocha": "latest" + } +} \ No newline at end of file diff --git a/node_modules/asteroid-module/test/asteroid-module.test.js b/node_modules/asteroid-module/test/asteroid-module.test.js new file mode 100644 index 00000000..9e9973a3 --- /dev/null +++ b/node_modules/asteroid-module/test/asteroid-module.test.js @@ -0,0 +1,24 @@ +var AsteroidModule = require('../'); + +describe('AsteroidModule', function(){ + var asteroidModule; + + beforeEach(function(){ + asteroidModule = new AsteroidModule; + }); + + describe('.myMethod', function(){ + // example sync test + it('should ', function() { + asteroidModule.myMethod(); + }); + + // example async test + it('should ', function(done) { + setTimeout(function () { + asteroidModule.myMethod(); + done(); + }, 0); + }); + }); +}); \ No newline at end of file diff --git a/node_modules/asteroid-module/test/support.js b/node_modules/asteroid-module/test/support.js new file mode 100644 index 00000000..a9572cf5 --- /dev/null +++ b/node_modules/asteroid-module/test/support.js @@ -0,0 +1,5 @@ +/** + * asteroid-module test setup and support. + */ + +assert = require('assert'); \ No newline at end of file diff --git a/node_modules/collection/.gitignore b/node_modules/collection/.gitignore new file mode 100644 index 00000000..6af74074 --- /dev/null +++ b/node_modules/collection/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.swp +*.swo +node_modules/ diff --git a/node_modules/collection/README.md b/node_modules/collection/README.md new file mode 100644 index 00000000..f5493391 --- /dev/null +++ b/node_modules/collection/README.md @@ -0,0 +1,13 @@ +# collection +v0.0.1 + +## Install + + slnode install collection + +## Example + + var Collection = require('collection'); + var collection = Collection.create(); + + collection.myMethod(); \ No newline at end of file diff --git a/node_modules/collection/example/example.js b/node_modules/collection/example/example.js new file mode 100644 index 00000000..0f9478af --- /dev/null +++ b/node_modules/collection/example/example.js @@ -0,0 +1,12 @@ +/** + * 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(); \ No newline at end of file diff --git a/node_modules/collection/index.js b/node_modules/collection/index.js new file mode 100644 index 00000000..86f4820e --- /dev/null +++ b/node_modules/collection/index.js @@ -0,0 +1,5 @@ +/** + * collection ~ public api + */ + +module.exports = require('./lib/collection'); \ No newline at end of file diff --git a/node_modules/collection/lib/collection.js b/node_modules/collection/lib/collection.js new file mode 100644 index 00000000..65236f00 --- /dev/null +++ b/node_modules/collection/lib/collection.js @@ -0,0 +1,105 @@ +/** + * Expose `Collection`. + */ + +module.exports = Collection; + +/** + * Module dependencies. + */ + +var Resource = require('resource').Resource + , debug = require('debug')('collection') + , util = require('util') + , inherits = util.inherits + , assert = require('assert'); + +/** + * Create a new `Collection` with the given `options`. + * + * @param {Object} options + * @return {Collection} + */ + +function Collection(options) { + Resource.apply(this, arguments); + + this.options = options; + + // collection middleware + this.app.use(function (req, res, next) { + req.asyncEmit('request', next); + }); + + // setup http routes + // this.setupRoutes(this.app); + + debug('created with options', options); +} + +/** + * Inherit from `Resource`. + */ + +inherits(Collection, Resource); + +/** + * Dependencies. + */ + +Collection.dependencies = { + 'store': 'store' +} + +Collection.prototype.setupRoutes = function (app) { + var store = this.store; + var done = this.done; + var Model = this.store; + var emit = this.asyncEmit; + + // create + app.post('/', create); + app.post('/new', create); + + function create(req, res, next) { + req.asyncEmit('create', function () { + var o = store.save(req.body, res.done); + }); + } + + // read + app.get('/:id', query); + app.get('/', query); + + function query(req, res, next) { + var query = req.query; + query.where = query.where || {}; + + if(req.param('id')) { + query.where.id = req.param('id'); + } + if(query.where.id) { + query.limit = 1; + } + + req.asyncEmit('query', query, function () { + store.all(query, res.done); + }); + } + + // update + app.put('/:id', function (req, res) { + req.asyncEmit('update', req.body, function () { + store.updateAttributes(req.body, res.done); + }); + }); + + // delete + app.destroy('/:id', function () { + var id = req.param('id'); + + req.asyncEmit('delete', id, function () { + store.destroy(id, res.done); + }); + }); +} \ No newline at end of file diff --git a/node_modules/collection/package.json b/node_modules/collection/package.json new file mode 100644 index 00000000..e6703feb --- /dev/null +++ b/node_modules/collection/package.json @@ -0,0 +1,15 @@ +{ + "name": "collection", + "description": "collection", + "version": "0.0.1", + "scripts": { + "test": "mocha" + }, + "dependencies": { + "debug": "latest", + "jugglingdb": "~0.2.0-29" + }, + "devDependencies": { + "mocha": "latest" + } +} diff --git a/node_modules/collection/test/collection.test.js b/node_modules/collection/test/collection.test.js new file mode 100644 index 00000000..14989c94 --- /dev/null +++ b/node_modules/collection/test/collection.test.js @@ -0,0 +1,24 @@ +var Collection = require('../'); + +describe('Collection', function(){ + var collection; + + beforeEach(function(){ + collection = new Collection; + }); + + describe('.myMethod', function(){ + // example sync test + it('should ', function() { + collection.myMethod(); + }); + + // example async test + it('should ', function(done) { + setTimeout(function () { + collection.myMethod(); + done(); + }, 0); + }); + }); +}); \ No newline at end of file diff --git a/node_modules/collection/test/support.js b/node_modules/collection/test/support.js new file mode 100644 index 00000000..efedb054 --- /dev/null +++ b/node_modules/collection/test/support.js @@ -0,0 +1,5 @@ +/** + * collection test setup and support. + */ + +assert = require('assert'); \ No newline at end of file diff --git a/node_modules/resource/.gitignore b/node_modules/resource/.gitignore new file mode 100644 index 00000000..6af74074 --- /dev/null +++ b/node_modules/resource/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.swp +*.swo +node_modules/ diff --git a/node_modules/resource/README.md b/node_modules/resource/README.md new file mode 100644 index 00000000..cb1f4eb0 --- /dev/null +++ b/node_modules/resource/README.md @@ -0,0 +1,73 @@ +# 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')`. + } + } + diff --git a/node_modules/resource/example/example.js b/node_modules/resource/example/example.js new file mode 100644 index 00000000..8626d855 --- /dev/null +++ b/node_modules/resource/example/example.js @@ -0,0 +1,12 @@ +/** + * 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(); \ No newline at end of file diff --git a/node_modules/resource/index.js b/node_modules/resource/index.js new file mode 100644 index 00000000..4a0c2513 --- /dev/null +++ b/node_modules/resource/index.js @@ -0,0 +1,5 @@ +/** + * resource ~ public api + */ + +module.exports = require('./lib/resource'); \ No newline at end of file diff --git a/node_modules/resource/lib/resource.js b/node_modules/resource/lib/resource.js new file mode 100644 index 00000000..7d9e3065 --- /dev/null +++ b/node_modules/resource/lib/resource.js @@ -0,0 +1,56 @@ +/** + * Expose `Resource`. + */ + +module.exports = Resource; + +/** + * Module dependencies. + */ + +var asteroid = require('asteroid') + , AsteroidModule = require('asteroid-module') + , debug = require('debug')('asteroid:resource') + , util = require('util') + , inherits = util.inherits + , assert = require('assert'); + +/** + * Create a new `Resource` with the given `options`. + * + * @param {Object} options + * @return {Resource} + */ + +function Resource(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'); + + // create the sub app + var app = this.app = asteroid(); + + this.options = options; + + debug('created with options', options); + + this.on('destroyed', function () { + app.disuse(this.options.path); + }); +} + +/** + * Inherit from `AsteroidModule`. + */ + +inherits(Resource, AsteroidModule); + +/** + * Mount the sub app on the given parent app at the configured path. + */ + +Resource.prototype.mount = function (parent) { + parent.use(this.options.path, this.app); +} \ No newline at end of file diff --git a/node_modules/resource/package.json b/node_modules/resource/package.json new file mode 100644 index 00000000..db5da708 --- /dev/null +++ b/node_modules/resource/package.json @@ -0,0 +1,14 @@ +{ + "name": "resource", + "description": "resource", + "version": "0.0.1", + "scripts": { + "test": "mocha" + }, + "dependencies": { + "debug": "latest" + }, + "devDependencies": { + "mocha": "latest" + } +} \ No newline at end of file diff --git a/node_modules/resource/test/resource.test.js b/node_modules/resource/test/resource.test.js new file mode 100644 index 00000000..9b03f471 --- /dev/null +++ b/node_modules/resource/test/resource.test.js @@ -0,0 +1,24 @@ +var Resource = require('../'); + +describe('Resource', function(){ + var resource; + + beforeEach(function(){ + resource = new Resource; + }); + + describe('.myMethod', function(){ + // example sync test + it('should ', function() { + resource.myMethod(); + }); + + // example async test + it('should ', function(done) { + setTimeout(function () { + resource.myMethod(); + done(); + }, 0); + }); + }); +}); \ No newline at end of file diff --git a/node_modules/resource/test/support.js b/node_modules/resource/test/support.js new file mode 100644 index 00000000..94e12000 --- /dev/null +++ b/node_modules/resource/test/support.js @@ -0,0 +1,5 @@ +/** + * resource test setup and support. + */ + +assert = require('assert'); \ No newline at end of file