From 279ce5b92948be7cbcb01026c40684bea551094b Mon Sep 17 00:00:00 2001 From: Ritchie Date: Thu, 23 May 2013 09:53:42 -0700 Subject: [PATCH] remove model-route --- lib/application.js | 34 ++++- node_modules/model-route/.gitignore | 10 -- node_modules/model-route/README.md | 21 ---- node_modules/model-route/index.js | 5 - node_modules/model-route/lib/model-route.js | 132 -------------------- node_modules/model-route/package.json | 14 --- package.json | 3 +- 7 files changed, 33 insertions(+), 186 deletions(-) delete mode 100644 node_modules/model-route/.gitignore delete mode 100644 node_modules/model-route/README.md delete mode 100644 node_modules/model-route/index.js delete mode 100644 node_modules/model-route/lib/model-route.js delete mode 100644 node_modules/model-route/package.json diff --git a/lib/application.js b/lib/application.js index e2d61b10..eb228127 100644 --- a/lib/application.js +++ b/lib/application.js @@ -4,7 +4,8 @@ var Model = require('../node_modules/model/lib/model') , DataSource = require('../node_modules/data-source') - , assert = require('assert'); + , assert = require('assert') + , RemoteObjects = require('sl-remoting'); /** * Export the app prototype. @@ -13,7 +14,19 @@ var Model = require('../node_modules/model/lib/model') var app = exports = module.exports = {}; /** - * Remove a route by referenve. + * Create a set of remote objects. + */ + +app.remotes = function () { + if(this._remotes) { + return this._remotes; + } else { + return (this._remotes = RemoteObjects.create()); + } +} + +/** + * Remove a route by reference. */ app.disuse = function (route) { @@ -39,8 +52,11 @@ app.models = {}; * @param options {Object} * @returns {Model} */ + app.defineModel = app.define = function (name, options) { + var remotes = this.remotes(); + options = options || {}; options.name = options.name || name; @@ -48,7 +64,19 @@ app.define = function (name, options) { assert(options.name, 'a name is required to define a model'); - return (this.model[name] = BaseModel.extend(options)); + var ModelCtor = (this.model[name] = BaseModel.extend(options)); + var proto = ModelCtor.prototype; + + remotes.exports[name] = ModelCtor; + + // default shared methods + if(ModelCtor.all) ModelCtor.all.shared = true; + if(proto.save) proto.save = true; + + // attach a remotes reference + ModelCtor.remotes = remotes; + + return ModelCtor; } /** diff --git a/node_modules/model-route/.gitignore b/node_modules/model-route/.gitignore deleted file mode 100644 index 6af74074..00000000 --- a/node_modules/model-route/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.DS_Store -*.seed -*.log -*.csv -*.dat -*.out -*.pid -*.swp -*.swo -node_modules/ diff --git a/node_modules/model-route/README.md b/node_modules/model-route/README.md deleted file mode 100644 index dce50557..00000000 --- a/node_modules/model-route/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# model route - -## About - -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](../route). - -### Options - -#### name (optional) - -If defined, overrides the default name (based on the path). - -### Dependencies - -#### model - -Requires a path to an existing model instance. diff --git a/node_modules/model-route/index.js b/node_modules/model-route/index.js deleted file mode 100644 index 22faf717..00000000 --- a/node_modules/model-route/index.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * collection ~ public api - */ - -module.exports = require('./lib/model-route'); \ No newline at end of file diff --git a/node_modules/model-route/lib/model-route.js b/node_modules/model-route/lib/model-route.js deleted file mode 100644 index 276c0992..00000000 --- a/node_modules/model-route/lib/model-route.js +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Expose `ModelRoute`. - */ - -module.exports = ModelRoute; - -/** - * Module dependencies. - */ - -var Route = require('route') - , debug = require('debug')('collection') - , util = require('util') - , inherits = util.inherits - , assert = require('assert'); - -/** - * Create a new `ModelRoute` with the given `options`. - * - * @param {Object} options - * @return {ModelRoute} - */ - -function ModelRoute(options) { - Route.apply(this, arguments); - - this.options = options; - - // model - this.model = this.dependencies.model.schema; - - // setup http routes - this.setupRoutes(this.app); - - debug('created with options', options); -} - -/** - * Inherit from `Route`. - */ - -inherits(ModelRoute, Route); - -/** - * Dependencies. - */ - -ModelRoute.dependencies = { - 'model': 'model' -} - -ModelRoute.prototype.setupRoutes = function (app) { - var Model = this.model; - var ctx; - var collection = this; - - app.use(function (req, res, next) { - ctx = collection.createContext(req, res, next); - - ctx.emit('request', function () { - ctx.emit(req.method.toLowerCase(), function () { - next(); - }); - }); - }); - - // create - app.post('/', create); - app.post('/new', create); - - function create(req, res, next) { - ctx.emit('create', function (done) { - Model.create(req.body, 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; - } - - if(query.limit) query.limit = Number(query.limit); - if(query.skip) query.skip = Number(query.skip); - - ctx.emit('query', query, function (done) { - Model.all(query, done); - }); - } - - // update - app.put('/:id', function (req, res) { - var body = req.body || {}; - var id = req.param('id'); - - if(Number(id) == id) { - id = Number(id); - } - - ctx.emit('find', function () { - Model.find(id, function (err, m) { - if(err) { - ctx.done(err); - } else { - ctx.emit('validate', body, function () { - ctx.emit('update', body, function (done) { - m.updateAttributes(body, done); - }); - }); - } - }); - }); - }); - - // delete - app.del('/:id', function () { - var id = req.param('id'); - - ctx.emit('delete', id, function (done) { - Model.destroy(id, done); - }); - }); -} \ No newline at end of file diff --git a/node_modules/model-route/package.json b/node_modules/model-route/package.json deleted file mode 100644 index 76571848..00000000 --- a/node_modules/model-route/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "model-route", - "description": "model-route", - "version": "0.0.1", - "scripts": { - "test": "mocha" - }, - "dependencies": { - "debug": "latest" - }, - "devDependencies": { - "mocha": "latest" - } -} diff --git a/package.json b/package.json index 54de78c6..779e4c72 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,10 @@ "dependencies": { "debug": "latest", "express": "~3.1.1", - "jugglingdb": "~0.2.0-30", + "jugglingdb": "git@github.com:strongloop/jugglingdb.git", "merge": "~1.1.0", "sl-module-loader": "git+ssh://git@github.com:strongloop/sl-module-loader.git" + "sl-remoting": "git+ssh://git@github.com:strongloop/sl-remoting.git" }, "devDependencies": { "mocha": "latest"