rename asteroid to loopback

This commit is contained in:
Raymond Feng 2013-07-16 10:42:47 -07:00
parent e810213590
commit a35d2b7365
17 changed files with 138 additions and 138 deletions

114
README.md
View File

@ -1,10 +1,10 @@
# asteroid
# loopback
v0.9.0
## Install
slnode install asteroid -g
slnode install loopback -g
## Server API
@ -13,7 +13,7 @@ v0.9.0
- [DataSource](#data-source)
- [Connectors](#connectors)
- [GeoPoint](#geo-point)
- [Asteroid Types](#asteroid-types)
- [Loopback Types](#loopback-types)
- [REST Router](#rest-router)
## Client API
@ -22,10 +22,10 @@ _TODO_
### App
Create an asteroid application.
Create an loopback application.
var asteroid = require('asteroid');
var app = asteroid();
var loopback = require('loopback');
var app = loopback();
app.get('/', function(req, res){
res.send('hello world');
@ -43,11 +43,11 @@ Create an asteroid application.
Expose a `Model` to remote clients.
var memory = asteroid.createDataSource({connector: asteroid.Memory});
var memory = loopback.createDataSource({connector: loopback.Memory});
var Color = memory.createModel('color', {name: String});
app.model(Color);
app.use(asteroid.rest());
app.use(loopback.rest());
**Note:** this will expose all [shared methods](#shared-methods) on the model.
@ -63,10 +63,10 @@ Get the app's exposed models.
### Model
An Asteroid `Model` is a vanilla JavaScript class constructor with an attached set of properties and options. A `Model` instance is created by passing a data object containing properties to the `Model` constructor. A `Model` constructor will clean the object passed to it and only set the values matching the properties you define.
An Loopback `Model` is a vanilla JavaScript class constructor with an attached set of properties and options. A `Model` instance is created by passing a data object containing properties to the `Model` constructor. A `Model` constructor will clean the object passed to it and only set the values matching the properties you define.
// valid color
var Color = asteroid.createModel('color', {name: String});
var Color = loopback.createModel('color', {name: String});
var red = new Color({name: 'red'});
console.log(red.name); // red
@ -82,9 +82,9 @@ A model defines a list of property names, types and other validation metadata. A
Some [DataSources](#data-source) may support additional `Model` options.
Define an asteroid model.
Define an loopback model.
var User = asteroid.createModel('user', {
var User = loopback.createModel('user', {
first: String,
last: String,
age: Number
@ -142,7 +142,7 @@ Validate the model instance.
#### Model.properties
An object containing a normalized set of properties supplied to `asteroid.createModel(name, properties)`.
An object containing a normalized set of properties supplied to `loopback.createModel(name, properties)`.
Example:
@ -151,10 +151,10 @@ Example:
b: {type: 'Number'},
c: {type: 'String', min: 10, max: 100},
d: Date,
e: asteroid.GeoPoint
e: loopback.GeoPoint
};
var MyModel = asteroid.createModel('foo', props);
var MyModel = loopback.createModel('foo', props);
console.log(MyModel.properties);
@ -179,8 +179,8 @@ Outputs:
Attach a model to a [DataSource](#data-source). Attaching a [DataSource](#data-source) updates the model with additional methods and behaviors.
var oracle = asteroid.createDataSource({
connector: require('asteroid-connector-oracle'),
var oracle = loopback.createDataSource({
connector: require('loopback-connector-oracle'),
host: '111.22.333.44',
database: 'MYDB',
username: 'username',
@ -284,7 +284,7 @@ Define a static model method.
Setup the static model method to be exposed to clients as a [remote method](#remote-method).
asteroid.remoteMethod(
loopback.remoteMethod(
User.login,
{
accepts: [
@ -338,13 +338,13 @@ Define an instance method.
Define a remote model instance method.
asteroid.remoteMethod(User.prototype.logout);
loopback.remoteMethod(User.prototype.logout);
#### Remote Methods
Both instance and static methods can be exposed to clients. A remote method must accept a callback with the conventional `fn(err, result, ...)` signature.
##### asteroid.remoteMethod(fn, [options]);
##### loopback.remoteMethod(fn, [options]);
Expose a remote method.
@ -352,7 +352,7 @@ Expose a remote method.
myApi.getStats('products', fn);
}
asteroid.remoteMethod(
loopback.remoteMethod(
Product.stats,
{
returns: {arg: 'stats', type: 'array'},
@ -382,7 +382,7 @@ An arguments description defines either a single argument as an object or an ord
**Types**
Each argument may define any of the [asteroid types](#asteroid-types).
Each argument may define any of the [loopback types](#loopback-types).
**Notes:**
@ -452,7 +452,7 @@ During `afterRemote` hooks, `ctx.result` will contain the data about to be sent
##### Rest
When [asteroid.rest](#asteroidrest) is used the following `ctx` properties are available.
When [loopback.rest](#loopbackrest) is used the following `ctx` properties are available.
###### ctx.req
@ -510,15 +510,15 @@ TODO: implement / document
#### Shared Methods
Any static or instance method can be decorated as `shared`. These methods are exposed over the provided transport (eg. [asteroid.rest](#rest)).
Any static or instance method can be decorated as `shared`. These methods are exposed over the provided transport (eg. [loopback.rest](#rest)).
### Data Source
An Asteroid `DataSource` provides [Models](#model) with the ability to manipulate data. Attaching a `DataSource` to a `Model` adds [instance methods](#instance-methods) and [static methods](#static-methods) to the `Model`. The added methods may be [remote methods](#remote-methods).
An Loopback `DataSource` provides [Models](#model) with the ability to manipulate data. Attaching a `DataSource` to a `Model` adds [instance methods](#instance-methods) and [static methods](#static-methods) to the `Model`. The added methods may be [remote methods](#remote-methods).
Define a data source for persisting models.
var oracle = asteroid.createDataSource({
var oracle = loopback.createDataSource({
connector: 'oracle',
host: '111.22.333.44',
database: 'MYDB',
@ -653,8 +653,8 @@ Disable remote access to a data source operation. Each [connector](#connector) h
// all rest data source operations are
// disabled by default
var oracle = asteroid.createDataSource({
connector: require('asteroid-connector-oracle'),
var oracle = loopback.createDataSource({
connector: require('loopback-connector-oracle'),
host: '...',
...
});
@ -697,22 +697,22 @@ Output:
Create a data source with a specific connector. See **available connectors** for specific connector documentation.
var memory = asteroid.createDataSource({
connector: asteroid.Memory
var memory = loopback.createDataSource({
connector: loopback.Memory
});
**Available Connectors**
- [Oracle](http://github.com/strongloop/asteroid-connectors/oracle)
- [In Memory](http://github.com/strongloop/asteroid-connectors/memory)
- TODO - [REST](http://github.com/strongloop/asteroid-connectors/rest)
- TODO - [MySQL](http://github.com/strongloop/asteroid-connectors/mysql)
- TODO - [SQLite3](http://github.com/strongloop/asteroid-connectors/sqlite)
- TODO - [Postgres](http://github.com/strongloop/asteroid-connectors/postgres)
- TODO - [Redis](http://github.com/strongloop/asteroid-connectors/redis)
- TODO - [MongoDB](http://github.com/strongloop/asteroid-connectors/mongo)
- TODO - [CouchDB](http://github.com/strongloop/asteroid-connectors/couch)
- TODO - [Firebird](http://github.com/strongloop/asteroid-connectors/firebird)
- [Oracle](http://github.com/strongloop/loopback-connectors/oracle)
- [In Memory](http://github.com/strongloop/loopback-connectors/memory)
- TODO - [REST](http://github.com/strongloop/loopback-connectors/rest)
- TODO - [MySQL](http://github.com/strongloop/loopback-connectors/mysql)
- TODO - [SQLite3](http://github.com/strongloop/loopback-connectors/sqlite)
- TODO - [Postgres](http://github.com/strongloop/loopback-connectors/postgres)
- TODO - [Redis](http://github.com/strongloop/loopback-connectors/redis)
- TODO - [MongoDB](http://github.com/strongloop/loopback-connectors/mongo)
- TODO - [CouchDB](http://github.com/strongloop/loopback-connectors/couch)
- TODO - [Firebird](http://github.com/strongloop/loopback-connectors/firebird)
**Installing Connectors**
@ -720,7 +720,7 @@ Include the connector in your package.json dependencies and run `npm install`.
{
"dependencies": {
"asteroid-connector-oracle": "latest"
"loopback-connector-oracle": "latest"
}
}
@ -728,15 +728,15 @@ Include the connector in your package.json dependencies and run `npm install`.
Use the `GeoPoint` class.
var GeoPoint = require('asteroid').GeoPoint;
var GeoPoint = require('loopback').GeoPoint;
Embed a latitude / longitude point in a [Model](#model).
var CoffeeShop = asteroid.createModel('coffee-shop', {
var CoffeeShop = loopback.createModel('coffee-shop', {
location: 'GeoPoint'
});
Asteroid Model's with a GeoPoint property and an attached DataSource may be queried using geo spatial filters and sorting.
Loopback Model's with a GeoPoint property and an attached DataSource may be queried using geo spatial filters and sorting.
Find the 3 nearest coffee shops.
@ -780,9 +780,9 @@ The latitude point in degrees. Range: -90 to 90.
The longitude point in degrees. Range: -180 to 180.
### Asteroid Types
### Loopback Types
Various APIs in Asteroid accept type descriptions (eg. [remote methods](#remote-methods), [asteroid.createModel()](#model)). The following is a list of supported types.
Various APIs in Loopback accept type descriptions (eg. [remote methods](#remote-methods), [loopback.createModel()](#model)). The following is a list of supported types.
- `null` - JSON null
- `Boolean` - JSON boolean
@ -792,11 +792,11 @@ Various APIs in Asteroid accept type descriptions (eg. [remote methods](#remote-
- `Array` - JSON array
- `Date` - a JavaScript date object
- `Buffer` - a node.js Buffer object
- [GeoPoint](#geopoint) - an asteroid GeoPoint object. TODO
- [GeoPoint](#geopoint) - an loopback GeoPoint object. TODO
#### Bundled Models
The Asteroid library is unopinioned in the way you define your app's data and logic. Asteroid also bundles useful pre-built models for common use cases.
The Loopback library is unopinioned in the way you define your app's data and logic. Loopback also bundles useful pre-built models for common use cases.
- User - _TODO_ register and authenticate users of your app locally or against 3rd party services.
- Notification - _TODO_ create, store, schedule and send push notifications to your app users.
@ -809,10 +809,10 @@ Register and authenticate users of your app locally or against 3rd party service
#### Create a User Model
Extend a vanilla Asteroid model using the built in User model.
Extend a vanilla Loopback model using the built in User model.
// define a User model
var User = asteroid.createModel(
var User = loopback.createModel(
'user',
{
email: {
@ -923,7 +923,7 @@ You must provide a username and password over rest. To ensure these values are e
To require email verification before a user is allowed to login, supply a verification property with a `verify` settings object.
// define a User model
var User = asteroid.createModel(
var User = loopback.createModel(
'user',
{
email: {
@ -971,17 +971,17 @@ Send an email to the user's supplied email address containing a link to reset th
#### Remote Password Reset
The password reset email will send users to a page rendered by asteroid with fields required to reset the user's password. You may customize this template by providing a `resetTemplate` option when defining your user model.
The password reset email will send users to a page rendered by loopback with fields required to reset the user's password. You may customize this template by providing a `resetTemplate` option when defining your user model.
### Email Model
Send emails from your asteroid app.
Send emails from your loopback app.
### REST Router
Expose models over rest using the `asteroid.rest` router.
Expose models over rest using the `loopback.rest` router.
app.use(asteroid.rest());
app.use(loopback.rest());
**REST Documentation**
@ -989,7 +989,7 @@ View generated REST documentation by visiting: [http://localhost:3000/_docs](htt
### SocketIO Middleware **Not Available**
**Coming Soon** - Expose models over socket.io using the `asteroid.sio()` middleware.
**Coming Soon** - Expose models over socket.io using the `loopback.sio()` middleware.
app.use(asteroid.sio);
app.use(loopback.sio);

View File

@ -1,7 +1,7 @@
var asteroid = require('../../');
var app = asteroid();
var loopback = require('../../');
var app = loopback();
app.use(asteroid.rest());
app.use(loopback.rest());
var schema = {
name: String

View File

@ -1,11 +1,11 @@
var models = require('../../lib/models');
var asteroid = require('../../');
var app = asteroid();
var loopback = require('../../');
var app = loopback();
app.use(asteroid.rest());
app.use(loopback.rest());
var dataSource = asteroid.createDataSource('db', {connector: asteroid.Memory});
var dataSource = loopback.createDataSource('db', {connector: loopback.Memory});
var Application = models.Application(dataSource);

View File

@ -1,7 +1,7 @@
var asteroid = require('../../');
var app = asteroid();
var loopback = require('../../');
var app = loopback();
app.use(asteroid.rest());
app.use(loopback.rest());
var dataSource = app.dataSource('db', {adapter: 'memory'});

View File

@ -1,8 +1,8 @@
var asteroid = require('../../');
var app = asteroid();
var loopback = require('../../');
var app = loopback();
app.use(asteroid.configure());
app.use(asteroid.bodyParser());
app.use(asteroid.routes());
app.use(loopback.configure());
app.use(loopback.bodyParser());
app.use(loopback.routes());
app.listen(3000);

View File

@ -1,18 +1,18 @@
/**
* asteroid ~ public api
* loopback ~ public api
*/
var asteroid = module.exports = require('./lib/asteroid');
var loopback = module.exports = require('./lib/loopback');
/**
* Connectors
*/
asteroid.Connector = require('./lib/connectors/base-connector');
asteroid.Memory = require('./lib/connectors/memory');
loopback.Connector = require('./lib/connectors/base-connector');
loopback.Memory = require('./lib/connectors/memory');
/**
* Types
*/
asteroid.GeoPoint = require('jugglingdb/lib/geo').GeoPoint;
loopback.GeoPoint = require('jugglingdb/lib/geo').GeoPoint;

View File

@ -17,22 +17,22 @@ var express = require('express')
* Expose `createApplication()`.
*/
var asteroid = exports = module.exports = createApplication;
var loopback = exports = module.exports = createApplication;
/**
* Framework version.
*/
asteroid.version = require('../package.json').version;
loopback.version = require('../package.json').version;
/**
* Expose mime.
*/
asteroid.mime = express.mime;
loopback.mime = express.mime;
/**
* Create an asteroid application.
* Create an loopback application.
*
* @return {Function}
* @api public
@ -47,20 +47,20 @@ function createApplication() {
}
/**
* Expose express.middleware as asteroid.*
* for example `asteroid.errorHandler` etc.
* Expose express.middleware as loopback.*
* for example `loopback.errorHandler` etc.
*/
for (var key in express) {
Object.defineProperty(
asteroid
loopback
, key
, Object.getOwnPropertyDescriptor(express, key));
}
/**
* Expose additional asteroid middleware
* for example `asteroid.configure` etc.
* Expose additional loopback middleware
* for example `loopback.configure` etc.
*/
fs
@ -69,14 +69,14 @@ fs
return file.match(/\.js$/);
})
.forEach(function (m) {
asteroid[m.replace(/\.js$/, '')] = require('./middleware/' + m);
loopback[m.replace(/\.js$/, '')] = require('./middleware/' + m);
});
/**
* Error handler title
*/
asteroid.errorHandler.title = 'Asteroid';
loopback.errorHandler.title = 'Loopback';
/**
* Create a data source with passing the provided options to the connector.
@ -84,14 +84,14 @@ asteroid.errorHandler.title = 'Asteroid';
* @param {String} name (optional)
* @param {Object} options
*
* - connector - an asteroid connector
* - connector - an loopback connector
* - other values - see the specified `connector` docs
*/
asteroid.createDataSource = function (name, options) {
loopback.createDataSource = function (name, options) {
var ds = new DataSource(name, options);
ds.createModel = function (name, properties, settings) {
var ModelCtor = asteroid.createModel(name, properties, settings);
var ModelCtor = loopback.createModel(name, properties, settings);
ModelCtor.attachTo(ds);
var hasMany = ModelCtor.hasMany;
@ -149,7 +149,7 @@ asteroid.createDataSource = function (name, options) {
* @param {Object} options (optional)
*/
asteroid.createModel = function (name, properties, options) {
loopback.createModel = function (name, properties, options) {
assert(typeof name === 'string', 'Cannot create a model without a name');
var mb = new ModelBuilder();
@ -250,7 +250,7 @@ asteroid.createModel = function (name, properties, options) {
* @param {Object} options (optional)
*/
asteroid.remoteMethod = function (fn, options) {
loopback.remoteMethod = function (fn, options) {
fn.shared = true;
if(typeof options === 'object') {
Object.keys(options).forEach(function (key) {

View File

@ -2,7 +2,7 @@
* Module dependencies.
*/
var asteroid = require('../asteroid');
var loopback = require('../loopback');
var RemoteObjects = require('sl-remoting');
/**

View File

@ -80,7 +80,7 @@ var ApplicationSchema = {
var crypto = require('crypto');
function generateKey(hmacKey, algorithm) {
hmacKey = hmacKey || 'asteroid';
hmacKey = hmacKey || 'loopback';
algorithm = algorithm || 'sha256';
var hmac = crypto.createHmac(algorithm, hmacKey);
var buf = crypto.randomBytes(64);

View File

@ -1,6 +1,6 @@
{
"name": "asteroid",
"description": "asteroid",
"name": "loopback",
"description": "loopback",
"version": "0.9.0",
"scripts": {
"test": "mocha -R spec"

View File

@ -2,9 +2,9 @@
- [app](#app)
- [app.model(Model)](#app-appmodelmodel)
- [app.models()](#app-appmodels)
- [asteroid](#asteroid)
- [asteroid.createDataSource(options)](#asteroid-asteroidcreatedatasourceoptions)
- [asteroid.remoteMethod(Model, fn, [options]);](#asteroid-asteroidremotemethodmodel-fn-options)
- [loopback](#loopback)
- [loopback.createDataSource(options)](#loopback-loopbackcreatedatasourceoptions)
- [loopback.remoteMethod(Model, fn, [options]);](#loopback-loopbackremotemethodmodel-fn-options)
- [DataSource](#datasource)
- [dataSource.createModel(name, properties, settings)](#datasource-datasourcecreatemodelname-properties-settings)
- [dataSource.operations()](#datasource-datasourceoperations)
@ -42,7 +42,7 @@
Expose a `Model` to remote clients..
```js
var memory = asteroid.createDataSource({connector: asteroid.Memory});
var memory = loopback.createDataSource({connector: loopback.Memory});
var Color = memory.createModel('color', {name: String});
app.model(Color);
assert.equal(app.models().length, 1);
@ -53,38 +53,38 @@ assert.equal(app.models().length, 1);
Get the app's exposed models..
```js
var Color = asteroid.createModel('color', {name: String});
var Color = loopback.createModel('color', {name: String});
var models = app.models();
assert.equal(models.length, 1);
assert.equal(models[0].modelName, 'color');
```
<a name="asteroid"></a>
# asteroid
<a name="asteroid-asteroidcreatedatasourceoptions"></a>
## asteroid.createDataSource(options)
<a name="loopback"></a>
# loopback
<a name="loopback-loopbackcreatedatasourceoptions"></a>
## loopback.createDataSource(options)
Create a data source with a connector..
```js
var dataSource = asteroid.createDataSource({
connector: asteroid.Memory
var dataSource = loopback.createDataSource({
connector: loopback.Memory
});
assert(dataSource.connector());
```
<a name="asteroid-asteroidremotemethodmodel-fn-options"></a>
## asteroid.remoteMethod(Model, fn, [options]);
<a name="loopback-loopbackremotemethodmodel-fn-options"></a>
## loopback.remoteMethod(Model, fn, [options]);
Setup a remote method..
```js
var Product = asteroid.createModel('product', {price: Number});
var Product = loopback.createModel('product', {price: Number});
Product.stats = function(fn) {
// ...
}
asteroid.remoteMethod(
loopback.remoteMethod(
Product.stats,
{
returns: {arg: 'stats', type: 'array'},
@ -284,7 +284,7 @@ user.isValid(function (valid) {
Attach a model to a [DataSource](#data-source).
```js
var MyModel = asteroid.createModel('my-model', {name: String});
var MyModel = loopback.createModel('my-model', {name: String});
assert(MyModel.all === undefined, 'should not have data access methods');

View File

@ -2,7 +2,7 @@ describe('app', function() {
describe('app.model(Model)', function() {
it("Expose a `Model` to remote clients.", function() {
var memory = asteroid.createDataSource({connector: asteroid.Memory});
var memory = loopback.createDataSource({connector: loopback.Memory});
var Color = memory.createModel('color', {name: String});
app.model(Color);
assert.equal(app.models().length, 1);
@ -11,7 +11,7 @@ describe('app', function() {
describe('app.models()', function() {
it("Get the app's exposed models.", function() {
var Color = asteroid.createModel('color', {name: String});
var Color = loopback.createModel('color', {name: String});
var models = app.models();
assert.equal(models.length, 1);

View File

@ -2,8 +2,8 @@ describe('DataSource', function() {
var memory;
beforeEach(function(){
memory = asteroid.createDataSource({
connector: asteroid.Memory
memory = loopback.createDataSource({
connector: loopback.Memory
});
});

View File

@ -40,7 +40,7 @@ describe('GeoPoint', function() {
assert.equal(point.lat, 6.777);
});
it('Create as Model property', function() {
var Model = asteroid.createModel('geo-model', {
var Model = loopback.createModel('geo-model', {
geo: {type: 'GeoPoint'}
});

View File

@ -1,22 +1,22 @@
describe('asteroid', function() {
describe('asteroid.createDataSource(options)', function(){
describe('loopback', function() {
describe('loopback.createDataSource(options)', function(){
it('Create a data source with a connector.', function() {
var dataSource = asteroid.createDataSource({
connector: asteroid.Memory
var dataSource = loopback.createDataSource({
connector: loopback.Memory
});
assert(dataSource.connector());
});
});
describe('asteroid.remoteMethod(Model, fn, [options]);', function() {
describe('loopback.remoteMethod(Model, fn, [options]);', function() {
it("Setup a remote method.", function() {
var Product = asteroid.createModel('product', {price: Number});
var Product = loopback.createModel('product', {price: Number});
Product.stats = function(fn) {
// ...
}
asteroid.remoteMethod(
loopback.remoteMethod(
Product.stats,
{
returns: {arg: 'stats', type: 'array'},

View File

@ -3,7 +3,7 @@ describe('Model', function() {
var User, memory;
beforeEach(function () {
memory = asteroid.createDataSource({connector: asteroid.Memory});
memory = loopback.createDataSource({connector: loopback.Memory});
User = memory.createModel('user', {
'first': String,
'last': String,
@ -109,7 +109,7 @@ describe('Model', function() {
describe('Model.attachTo(dataSource)', function() {
it("Attach a model to a [DataSource](#data-source)", function() {
var MyModel = asteroid.createModel('my-model', {name: String});
var MyModel = loopback.createModel('my-model', {name: String});
assert(MyModel.find === undefined, 'should not have data access methods');
@ -254,7 +254,7 @@ describe('Model', function() {
}
}
asteroid.remoteMethod(
loopback.remoteMethod(
User.login,
{
accepts: [
@ -266,7 +266,7 @@ describe('Model', function() {
}
);
app.use(asteroid.rest());
app.use(loopback.rest());
app.model(User);
});
@ -433,16 +433,16 @@ describe('Model', function() {
});
describe('Model.properties', function(){
it('Normalized properties passed in originally by asteroid.createModel().', function() {
it('Normalized properties passed in originally by loopback.createModel().', function() {
var props = {
s: String,
n: {type: 'Number'},
o: {type: 'String', min: 10, max: 100},
d: Date,
g: asteroid.GeoPoint
g: loopback.GeoPoint
};
var MyModel = asteroid.createModel('foo', props);
var MyModel = loopback.createModel('foo', props);
Object.keys(MyModel.properties).forEach(function (key) {
var p = MyModel.properties[key];
@ -497,7 +497,7 @@ describe('Model', function() {
// },
// ...
// }
// var oracle = asteroid.createDataSource({
// var oracle = loopback.createDataSource({
// connector: 'oracle',
// host: '111.22.333.44',
// database: 'MYDB',

View File

@ -1,17 +1,17 @@
/**
* asteroid test setup and support.
* loopback test setup and support.
*/
assert = require('assert');
asteroid = require('../');
memoryConnector = asteroid.Memory;
GeoPoint = asteroid.GeoPoint;
loopback = require('../');
memoryConnector = loopback.Memory;
GeoPoint = loopback.GeoPoint;
app = null;
TaskEmitter = require('sl-task-emitter');
request = require('supertest');
beforeEach(function () {
app = asteroid();
app = loopback();
});
assertValidDataSource = function (dataSource) {