From a4fb3012bf37f5d8f8e8476eb7c187bf91f8ae7e Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Mon, 1 Jul 2013 10:41:52 -0700 Subject: [PATCH 01/10] Only build a sl remoting handler when a model is added to the app. --- lib/application.js | 53 ++++++++++++++++++++++++++---------------- lib/middleware/rest.js | 13 ++--------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/lib/application.js b/lib/application.js index 5094ae74..6f28fbbd 100644 --- a/lib/application.js +++ b/lib/application.js @@ -60,12 +60,20 @@ app._models = []; */ app.model = function (Model) { + var remotes = this.remotes(); + this._models.push(Model); Model.shared = true; Model.app = this; if(Model._remoteHooks) { Model._remoteHooks.emit('attached', app); } + + // add to the remote exports + remotes.exports[Model.pluralModelName] = Model; + + // clear the handlers cache + this._handlers = {}; } /** @@ -76,29 +84,34 @@ app.models = function () { return this._models; } -/** - * Get all remote objects. - */ - -app.remoteObjects = function () { - var result = {}; - var models = this.models(); - - // add in models - models.forEach(function (ModelCtor) { - // only add shared models - if(ModelCtor.shared && typeof ModelCtor.sharedCtor === 'function') { - result[ModelCtor.pluralModelName] = ModelCtor; - } - }); - - return result; -} - /** * Get the apps set of remote objects. */ app.remotes = function () { return this._remotes || (this._remotes = RemoteObjects.create()); -} \ No newline at end of file +} + +/** + * Get a remotes handler. + */ + +app.handler = function (type) { + var handler = this._handlers[type]; + + if(!handler) { + // get the sl remoting object + var remotes = this.remotes(); + + // create and save the handler + handler = this._handlers[type] = remotes.handler(type); + } + + return handler; +} + +/*! + * Handlers + */ + +app._handlers = {}; \ No newline at end of file diff --git a/lib/middleware/rest.js b/lib/middleware/rest.js index a22dadcf..5830ed71 100644 --- a/lib/middleware/rest.js +++ b/lib/middleware/rest.js @@ -17,21 +17,12 @@ module.exports = rest; function rest() { return function (req, res, next) { - var app = req.app; - var remotes = app.remotes(); - - // get all remote objects - var objs = app.remoteObjects(); - - // export remote objects - remotes.exports = objs; - - var handler = remotes.handler('rest'); + var handler = req.app.handler('rest'); if(req.url === '/routes') { res.send(handler.adapter.allRoutes()); } else if(req.url === '/models') { - return res.send(remotes.toJSON()); + return res.send(req.app.remotes().toJSON()); } else { handler(req, res, next); } From a228ade1b1f0ced61324d321d7d0c188a921dad2 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 1 Jul 2013 11:51:28 -0700 Subject: [PATCH 02/10] Add more information to the logical models --- lib/models/acl.js | 37 ++++++++++++++++++++++++++----------- lib/models/role.js | 6 +++--- lib/models/user.js | 14 ++++++++++++-- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/lib/models/acl.js b/lib/models/acl.js index d10f2c3c..07a941c0 100644 --- a/lib/models/acl.js +++ b/lib/models/acl.js @@ -1,17 +1,32 @@ -// Schema ACL options +/** +Schema ACL options +Object level permissions, for example, an album owned by a user -// Object level permissions +Factors to be authorized against: -// open: no protection -// none: always rejected -// owner: only the owner -// loggedIn: any logged in user -// roles: logged in users with the roles -// related: owner of the related objects +* model name: Album +* model instance properties: userId of the album, friends, shared +* methods +* app and/or user ids/roles + ** loggedIn + ** roles + ** userId + ** appId + ** none + ** everyone + ** relations: owner/friend/granted -// Class level permissions +Class level permissions, for example, Album + * model name: Album + * methods -// scopes +URL/Route level permissions + * url pattern + * application id + * ip addresses + * http headers -// URL level permissions \ No newline at end of file +Map to oAuth 2.0 scopes + +*/ \ No newline at end of file diff --git a/lib/models/role.js b/lib/models/role.js index a9546777..a04ad962 100644 --- a/lib/models/role.js +++ b/lib/models/role.js @@ -2,9 +2,9 @@ var RoleSchema = { id: {type: String, required: true}, name: {type: String, required: true}, - roles: [String], - users: [String], - acl: [], + roles: [String], // A role can be an aggregate of other roles + users: [String], // A role contains a list of users + acls: [], created: Date, lastUpdated: Date diff --git a/lib/models/user.js b/lib/models/user.js index 38d20452..ec63821a 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -1,11 +1,21 @@ // User model var UserSchema = { id: {type: String, required: true}, + realm: {type: String}, username: {type: String, required: true}, - password: String, - authData: [], + password: {type: String, transient: true}, // Transient property + hash: {type: String}, // Hash code calculated from sha256(realm, username, password, salt, macKey) + salt: {type: String}, + macKey: {type: String}, // HMAC to calculate the hash code email: String, emailVerified: Boolean, + credentials: [ + 'UserCredential' // User credentials, private or public, such as private/public keys, Kerberos tickets, oAuth tokens, facebook, google, github ids + ], + challenges: [ + 'Challenge' // Security questions/answers + ], + status: String, created: Date, lastUpdated: Date } \ No newline at end of file From 72020f8b627767a777e404fd57c96be6d9b47193 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 1 Jul 2013 15:53:10 -0700 Subject: [PATCH 03/10] Add more info to the models --- lib/models/acl.js | 13 ++++++++++++- lib/models/installation.js | 2 +- lib/models/role.js | 1 - lib/models/user.js | 21 ++++++++++++++++++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/models/acl.js b/lib/models/acl.js index 07a941c0..6b3f6d46 100644 --- a/lib/models/acl.js +++ b/lib/models/acl.js @@ -29,4 +29,15 @@ URL/Route level permissions Map to oAuth 2.0 scopes -*/ \ No newline at end of file +*/ + +var ACLSchema = { + model: String, // The model name + properties: [String], // A list of property names + methods: [String], // A list of methods + roles: [String], // A list of roles + permission: {type: String, enum: ['Allow', 'Deny']}, // Allow/Deny + status: String, // Enabled/disabled + created: Date, + lastUpdated: Date +} \ No newline at end of file diff --git a/lib/models/installation.js b/lib/models/installation.js index 37e8bd0d..03d1b0ed 100644 --- a/lib/models/installation.js +++ b/lib/models/installation.js @@ -1,4 +1,4 @@ -// Device registration +// See Device registration var InstallationSchema = { }; diff --git a/lib/models/role.js b/lib/models/role.js index a04ad962..0bd17dae 100644 --- a/lib/models/role.js +++ b/lib/models/role.js @@ -4,7 +4,6 @@ var RoleSchema = { name: {type: String, required: true}, roles: [String], // A role can be an aggregate of other roles users: [String], // A role contains a list of users - acls: [], created: Date, lastUpdated: Date diff --git a/lib/models/user.js b/lib/models/user.js index ec63821a..545e772c 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -1,9 +1,22 @@ +var ChallengeSchema = { + // id: String, + question: String, + answer: String +}; + +var Credential = { + // id: String, + provider: String, + protocol: String, + attributes: Object +} + // User model var UserSchema = { id: {type: String, required: true}, realm: {type: String}, username: {type: String, required: true}, - password: {type: String, transient: true}, // Transient property + // password: {type: String, transient: true}, // Transient property hash: {type: String}, // Hash code calculated from sha256(realm, username, password, salt, macKey) salt: {type: String}, macKey: {type: String}, // HMAC to calculate the hash code @@ -15,6 +28,12 @@ var UserSchema = { challenges: [ 'Challenge' // Security questions/answers ], + // https://en.wikipedia.org/wiki/Multi-factor_authentication + /* + factors: [ + 'AuthenticationFactor' + ], + */ status: String, created: Date, lastUpdated: Date From 3a420187e959844b7ebea4991a9163a546e135e4 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 2 Jul 2013 17:04:20 -0700 Subject: [PATCH 04/10] Add service method --- lib/application.js | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/application.js b/lib/application.js index 6f28fbbd..489467aa 100644 --- a/lib/application.js +++ b/lib/application.js @@ -25,6 +25,21 @@ app.remotes = function () { } } +/** + * Expose an object or Class remotely. + * + * @param {String} name The remote namespace (eg. url base) + * @param {Object|Function} obj The object to remote + */ + +app.remote = function (name, obj) { + // add the object to the remote exports + this.remotes().exports[name] = obj; + + // clear the handlers cache + this._handlers = {}; +} + /** * Remove a route by reference. */ @@ -70,10 +85,32 @@ app.model = function (Model) { } // add to the remote exports - remotes.exports[Model.pluralModelName] = Model; + this.remote(Model.pluralModelName, Model); +} + +/** + * Get all exposed models. + */ + +app.models = function () { + return this._models; +} + +/** + * Expose a service. + * + * @param {String} name + * @param {Service} service + */ + +app.service = function (name, service) { + this._services.push(service); + service.shared = true; - // clear the handlers cache - this._handlers = {}; + service.app = this; + + // add to the remote exports + this.remote(name, service); } /** From 9fe79dbfca6c9b7a6b17176bc74a7c62e1c5cad0 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 2 Jul 2013 17:22:51 -0700 Subject: [PATCH 05/10] Fix service() & services() --- lib/application.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/application.js b/lib/application.js index 489467aa..390bc68d 100644 --- a/lib/application.js +++ b/lib/application.js @@ -67,6 +67,7 @@ app.modelBuilder = function () { */ app._models = []; +app._services = []; /** * Expose a model. @@ -114,11 +115,11 @@ app.service = function (name, service) { } /** - * Get all exposed models. + * Get all exposed services. */ -app.models = function () { - return this._models; +app.services = function () { + return this._services; } /** @@ -151,4 +152,5 @@ app.handler = function (type) { * Handlers */ -app._handlers = {}; \ No newline at end of file +app._handlers = {}; + From b4391e6b261940bd1d27b96e2782699049ed5ec7 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 8 Jul 2013 16:59:11 -0700 Subject: [PATCH 06/10] Updating models --- lib/models/acl.js | 4 +++- lib/models/application.js | 37 ++++++++++++++++++++++++++----------- lib/models/installation.js | 15 ++++++++++++++- lib/models/role.js | 4 ++-- lib/models/user.js | 21 +++++++++++++++++++++ 5 files changed, 66 insertions(+), 15 deletions(-) diff --git a/lib/models/acl.js b/lib/models/acl.js index 6b3f6d46..db341f62 100644 --- a/lib/models/acl.js +++ b/lib/models/acl.js @@ -40,4 +40,6 @@ var ACLSchema = { status: String, // Enabled/disabled created: Date, lastUpdated: Date -} \ No newline at end of file +} + +// readAccess, writeAccess --> public, userId, role \ No newline at end of file diff --git a/lib/models/application.js b/lib/models/application.js index 173d2b97..b19b445b 100644 --- a/lib/models/application.js +++ b/lib/models/application.js @@ -1,17 +1,26 @@ -// Application model +/** + * Data model for Application + */ var ApplicationSchema = { // Basic information id: {type: String, required: true}, name: {type: String, required: true}, description: String, // description - icon: String, // The icon url - public: Boolean, + icon: String, // The icon image url + + public: Boolean, // Do we list the application in the public catalog? permissions: [String], - userId: String, + owner: String, // The user id of the developer who registers the application + collaborators: [String], // A list of users ids who have permissions to work on this app - status: String, + // EMail + email: String, // e-mail address + emailVerified: Boolean, // Is the e-mail verified + + + status: String, // Status of the application, enabled/disabled // Keys clientKey: String, @@ -24,18 +33,24 @@ var ApplicationSchema = { pushPlatforms: [String], pushCredentials: [], - // Authentication + // User Authentication authenticationEnabled: Boolean, anonymousAllowed: Boolean, schemes: [String], // Basic, facebook, github, google attachedCredentials: [], - // email - email: String, // e-mail address - emailVerified: Boolean, // Is the e-mail verified - - collaborators: [String], // A list of users ids who have permissions to work on this app created: Date, lastUpdated: Date }; + + +/** + * Application management functions + */ + +// Register a new application + + + + diff --git a/lib/models/installation.js b/lib/models/installation.js index 03d1b0ed..a734dc64 100644 --- a/lib/models/installation.js +++ b/lib/models/installation.js @@ -1,4 +1,17 @@ // See Device registration var InstallationSchema = { - + id: { + type: String, + required: true, + id: 1 + }, + appId: String, + appVersion: String, + userId: String, + deviceToken: String, + deviceType: String, + subscriptions: [String], + created: Date, + lastModified: Date, + status: String }; diff --git a/lib/models/role.js b/lib/models/role.js index 0bd17dae..74421708 100644 --- a/lib/models/role.js +++ b/lib/models/role.js @@ -1,10 +1,10 @@ // Role model var RoleSchema = { id: {type: String, required: true}, - name: {type: String, required: true}, + name: {type: String, required: true}, // The name of a role + description: String, roles: [String], // A role can be an aggregate of other roles users: [String], // A role contains a list of users - created: Date, lastUpdated: Date } \ No newline at end of file diff --git a/lib/models/user.js b/lib/models/user.js index 545e772c..0f170093 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -1,3 +1,24 @@ +/** + * User Model + Active User + Explicit vs. Implicit + Signup + Removing the User from the System + Login + Logout + User Management + Email Verification + Password Reset + Forgot Username + Using Social Identities + Facebook + Google+ + LinkedIn + Twitter + User Discovery + Username Existence Check + * @type {{question: *, answer: *}} + */ var ChallengeSchema = { // id: String, question: String, From 83ca45e07e09e1d4577b5e305a312d4eea4d0aae Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 9 Jul 2013 15:06:42 -0700 Subject: [PATCH 07/10] Add exports to models --- lib/models/acl.js | 10 ++++- lib/models/application.js | 81 ++++++++++++++++++++++++++++++-------- lib/models/index.js | 16 ++++++++ lib/models/installation.js | 21 +++++++--- lib/models/role.js | 18 ++++++--- lib/models/user.js | 2 +- 6 files changed, 117 insertions(+), 31 deletions(-) create mode 100644 lib/models/index.js diff --git a/lib/models/acl.js b/lib/models/acl.js index db341f62..9fe28310 100644 --- a/lib/models/acl.js +++ b/lib/models/acl.js @@ -39,7 +39,13 @@ var ACLSchema = { permission: {type: String, enum: ['Allow', 'Deny']}, // Allow/Deny status: String, // Enabled/disabled created: Date, - lastUpdated: Date + modified: Date } -// readAccess, writeAccess --> public, userId, role \ No newline at end of file +// readAccess, writeAccess --> public, userId, role + +module.exports = function(dataSource) { + dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + var ACL = dataSource.define('ACL', ACLSchema); + return ACL; +} \ No newline at end of file diff --git a/lib/models/application.js b/lib/models/application.js index b19b445b..c4761c5f 100644 --- a/lib/models/application.js +++ b/lib/models/application.js @@ -1,17 +1,26 @@ +// Authentication schemes +var AuthenticationScheme = { + scheme: String, // local, facebook, google, twitter, linkedin, github + credential: Object // Scheme-specific credentials +} + +// Push notification settings +var PushNotificationSetting = { + platform: {type: String, required: true}, // apns, gcm, mpns + configuration: Object // platform-specific configurations +} + /** * Data model for Application */ var ApplicationSchema = { // Basic information - id: {type: String, required: true}, - name: {type: String, required: true}, - description: String, // description + id: {type: String, required: true}, // The id + name: {type: String, required: true}, // The name + description: String, // The description icon: String, // The icon image url - public: Boolean, // Do we list the application in the public catalog? - permissions: [String], - owner: String, // The user id of the developer who registers the application collaborators: [String], // A list of users ids who have permissions to work on this app @@ -19,8 +28,10 @@ var ApplicationSchema = { email: String, // e-mail address emailVerified: Boolean, // Is the e-mail verified - - status: String, // Status of the application, enabled/disabled + // oAuth 2.0 settings + url: String, // The application url + callbackUrls: [String], // oAuth 2.0 code/token callback url + permissions: [String], // A list of permissions required by the application // Keys clientKey: String, @@ -30,18 +41,18 @@ var ApplicationSchema = { masterKey: String, // Push notification - pushPlatforms: [String], - pushCredentials: [], + pushSettings: [PushNotificationSetting], // User Authentication - authenticationEnabled: Boolean, - anonymousAllowed: Boolean, - schemes: [String], // Basic, facebook, github, google - attachedCredentials: [], + authenticationEnabled: {type: Boolean, default: true}, + anonymousAllowed: {type: Boolean, default: true}, + authenticationSchemes: [AuthenticationScheme], + status: {type: String, default: 'sandbox'}, // Status of the application, production/sandbox/disabled - created: Date, - lastUpdated: Date + // Timestamps + created: {type: Date, default: Date}, + modified: {type: Date, default: Date} }; @@ -49,7 +60,43 @@ var ApplicationSchema = { * Application management functions */ -// Register a new application +var crypto = require('crypto'); + +function generateKey(hmacKey, algorithm) { + hmacKey = hmacKey || 'asteroid'; + algorithm = algorithm || 'sha256'; + var hmac = crypto.createHmac(algorithm, hmacKey); + var buf = crypto.randomBytes(64); + hmac.update(buf); + return hmac.digest('base64'); +} + +module.exports = function (dataSource) { + dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + + + var Application = dataSource.define('Application', ApplicationSchema); + + Application.afterInitialize = function () { + var app = this; + // use data argument to update object + app.created = app.modified = new Date(); + app.id = generateKey('id', 'sha1'); + app.clientKey = generateKey('client'); + app.javaScriptKey = generateKey('javaScript'); + app.restApiKey = generateKey('restApi'); + app.windowsKey = generateKey('windows'); + app.masterKey = generateKey('master'); + }; + + // Register a new application + Application.register = function (name, description, owner) { + return new Application({name: name, description: description, owner: owner}); + } + + return Application; +} + diff --git a/lib/models/index.js b/lib/models/index.js new file mode 100644 index 00000000..f0d994ff --- /dev/null +++ b/lib/models/index.js @@ -0,0 +1,16 @@ +var ModelBuilder = require('jugglingdb').ModelBuilder; + +var ds = new ModelBuilder(); + +exports.Application = require('./application')(ds); +exports.ACL = require('./acl')(ds); +exports.Role = require('./role')(ds); +exports.Installation = require('./installation')(ds); + +/* +console.log(new exports.Role()); +console.log(new exports.ACL()); +console.log(new exports.Application()); +console.log(new exports.Installation()); +*/ + diff --git a/lib/models/installation.js b/lib/models/installation.js index a734dc64..28d8ee8d 100644 --- a/lib/models/installation.js +++ b/lib/models/installation.js @@ -5,13 +5,22 @@ var InstallationSchema = { required: true, id: 1 }, - appId: String, - appVersion: String, - userId: String, + appId: String, // Application id + appVersion: String, // Application version + userId: String, // User id deviceToken: String, deviceType: String, subscriptions: [String], - created: Date, - lastModified: Date, - status: String + + status: {type: String, default: 'active'}, // Status of the application, production/sandbox/disabled + + // Timestamps + created: {type: Date, default: Date}, + modified: {type: Date, default: Date} }; + +module.exports = function(dataSource) { + dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + var Installation = dataSource.define('Installation', InstallationSchema); + return Installation; +} diff --git a/lib/models/role.js b/lib/models/role.js index 74421708..5259d8b3 100644 --- a/lib/models/role.js +++ b/lib/models/role.js @@ -1,10 +1,18 @@ // Role model var RoleSchema = { - id: {type: String, required: true}, + id: {type: String, required: true}, // Id name: {type: String, required: true}, // The name of a role - description: String, + description: String, // Description roles: [String], // A role can be an aggregate of other roles - users: [String], // A role contains a list of users - created: Date, - lastUpdated: Date + users: [String], // A role contains a list of user ids + + // Timestamps + created: {type: Date, default: Date}, + modified: {type: Date, default: Date} +} + +module.exports = function(dataSource) { + dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + var Role = dataSource.define('Role', RoleSchema); + return Role; } \ No newline at end of file diff --git a/lib/models/user.js b/lib/models/user.js index 0f170093..02215c31 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -57,5 +57,5 @@ var UserSchema = { */ status: String, created: Date, - lastUpdated: Date + modified: Date } \ No newline at end of file From e8102135909b7b1cf0269804c17287025194a47a Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 12 Jul 2013 13:09:22 -0700 Subject: [PATCH 08/10] Experiment application model --- example/mobile-models/app.js | 45 +++++++++++++++++++++++++++++++++ lib/models/application.js | 48 ++++++++++++++++++++++++++++++------ lib/models/index.js | 18 +++----------- 3 files changed, 90 insertions(+), 21 deletions(-) create mode 100644 example/mobile-models/app.js diff --git a/example/mobile-models/app.js b/example/mobile-models/app.js new file mode 100644 index 00000000..5a83e9f4 --- /dev/null +++ b/example/mobile-models/app.js @@ -0,0 +1,45 @@ +var models = require('../../lib/models'); + +var asteroid = require('../../'); +var app = asteroid(); + +app.use(asteroid.rest()); + +var dataSource = asteroid.createDataSource('db', {connector: asteroid.Memory}); + +var Application = models.Application(dataSource); + +app.model(Application); + + +var data = {pushSettings: [ + { "platform": "apns", + "apns": { + "pushOptions": { + "gateway": "gateway.sandbox.push.apple.com", + "cert": "credentials/apns_cert_dev.pem", + "key": "credentials/apns_key_dev.pem" + }, + + "feedbackOptions": { + "gateway": "feedback.sandbox.push.apple.com", + "cert": "credentials/apns_cert_dev.pem", + "key": "credentials/apns_key_dev.pem", + "batchFeedback": true, + "interval": 300 + } + }} +]} + +Application.create(data, function(err, data) { + console.log('Created: ', data.toObject()); +}); + + +Application.register('MyApp', 'My first mobile application', 'rfeng', function (err, result) { + console.log(result.toObject()); + + result.resetKeys(function (err, result) { + console.log(result.toObject()); + }); +}); diff --git a/lib/models/application.js b/lib/models/application.js index c4761c5f..a9664b13 100644 --- a/lib/models/application.js +++ b/lib/models/application.js @@ -1,13 +1,30 @@ // Authentication schemes -var AuthenticationScheme = { +var AuthenticationSchemeSchema = { scheme: String, // local, facebook, google, twitter, linkedin, github credential: Object // Scheme-specific credentials } +var APNSSettingSchema = { + pushOptions: {type: { + gateway: String, + cert: String, + key: String + }}, + + feedbackOptions: {type: { + gateway: String, + cert: String, + key: String, + batchFeedback: Boolean, + interval: Number + }} +}; + // Push notification settings -var PushNotificationSetting = { +var PushNotificationSettingSchema = { platform: {type: String, required: true}, // apns, gcm, mpns - configuration: Object // platform-specific configurations + // configuration: {type: Object} // platform-specific configurations + apns: APNSSettingSchema } /** @@ -41,12 +58,12 @@ var ApplicationSchema = { masterKey: String, // Push notification - pushSettings: [PushNotificationSetting], + pushSettings: [PushNotificationSettingSchema], // User Authentication authenticationEnabled: {type: Boolean, default: true}, anonymousAllowed: {type: Boolean, default: true}, - authenticationSchemes: [AuthenticationScheme], + authenticationSchemes: [AuthenticationSchemeSchema], status: {type: String, default: 'sandbox'}, // Status of the application, production/sandbox/disabled @@ -74,9 +91,17 @@ function generateKey(hmacKey, algorithm) { module.exports = function (dataSource) { dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + // var AuthenticationScheme = dataSource.define('AuthenticationScheme', AuthenticationSchemeSchema); + // ApplicationSchema.authenticationSchemes = [AuthenticationScheme]; + + // var PushNotificationSetting = dataSource.define('PushNotificationSetting', PushNotificationSettingSchema); + // ApplicationSchema.pushSettings = [PushNotificationSetting]; var Application = dataSource.define('Application', ApplicationSchema); + // Application.hasMany(AuthenticationScheme, {as: 'authenticationSchemes', foreignKey: 'appId'}); + // Application.hasMany(PushNotificationSetting, {as: 'pushNotificationSettings', foreignKey: 'appId'}); + Application.afterInitialize = function () { var app = this; // use data argument to update object @@ -90,8 +115,17 @@ module.exports = function (dataSource) { }; // Register a new application - Application.register = function (name, description, owner) { - return new Application({name: name, description: description, owner: owner}); + Application.register = function (name, description, owner, cb) { + Application.create({name: name, description: description, owner: owner}, cb); + } + + Application.prototype.resetKeys = function(cb) { + this.clientKey = generateKey('client'); + this.javaScriptKey = generateKey('javaScript'); + this.restApiKey = generateKey('restApi'); + this.windowsKey = generateKey('windows'); + this.masterKey = generateKey('master'); + this.save(cb); } return Application; diff --git a/lib/models/index.js b/lib/models/index.js index f0d994ff..35f6a412 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -1,16 +1,6 @@ -var ModelBuilder = require('jugglingdb').ModelBuilder; +exports.Application = require('./application'); +exports.ACL = require('./acl'); +exports.Role = require('./role'); +exports.Installation = require('./installation'); -var ds = new ModelBuilder(); - -exports.Application = require('./application')(ds); -exports.ACL = require('./acl')(ds); -exports.Role = require('./role')(ds); -exports.Installation = require('./installation')(ds); - -/* -console.log(new exports.Role()); -console.log(new exports.ACL()); -console.log(new exports.Application()); -console.log(new exports.Installation()); -*/ From a35d2b7365d720e4786d6cd899bb7866bca20a3b Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 16 Jul 2013 10:42:47 -0700 Subject: [PATCH 09/10] rename asteroid to loopback --- README.md | 114 ++++++++++---------- example/colors/app.js | 6 +- example/mobile-models/app.js | 8 +- example/simple-data-source/app.js | 6 +- example/todos/app.js | 10 +- index.js | 10 +- lib/{asteroid.js => loopback.js} | 32 +++--- lib/middleware/rest.js | 2 +- lib/models/application.js | 2 +- package.json | 4 +- test/README.md | 32 +++--- test/app.test.js | 4 +- test/data-source.test.js | 4 +- test/geo-point.test.js | 2 +- test/{asteroid.test.js => loopback.test.js} | 14 +-- test/model.test.js | 16 +-- test/support.js | 10 +- 17 files changed, 138 insertions(+), 138 deletions(-) rename lib/{asteroid.js => loopback.js} (88%) rename test/{asteroid.test.js => loopback.test.js} (67%) diff --git a/README.md b/README.md index 0baadbca..14a66f62 100644 --- a/README.md +++ b/README.md @@ -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); diff --git a/example/colors/app.js b/example/colors/app.js index 5572b2e2..a7fdb01f 100644 --- a/example/colors/app.js +++ b/example/colors/app.js @@ -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 diff --git a/example/mobile-models/app.js b/example/mobile-models/app.js index 5a83e9f4..f671f360 100644 --- a/example/mobile-models/app.js +++ b/example/mobile-models/app.js @@ -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); diff --git a/example/simple-data-source/app.js b/example/simple-data-source/app.js index 9b4f0569..08d6d94a 100644 --- a/example/simple-data-source/app.js +++ b/example/simple-data-source/app.js @@ -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'}); diff --git a/example/todos/app.js b/example/todos/app.js index f5411dc5..8a2dd304 100644 --- a/example/todos/app.js +++ b/example/todos/app.js @@ -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); \ No newline at end of file diff --git a/index.js b/index.js index 39bdd874..e5802780 100644 --- a/index.js +++ b/index.js @@ -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; \ No newline at end of file +loopback.GeoPoint = require('jugglingdb/lib/geo').GeoPoint; \ No newline at end of file diff --git a/lib/asteroid.js b/lib/loopback.js similarity index 88% rename from lib/asteroid.js rename to lib/loopback.js index 4cb569bf..c97a73d2 100644 --- a/lib/asteroid.js +++ b/lib/loopback.js @@ -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) { diff --git a/lib/middleware/rest.js b/lib/middleware/rest.js index 5830ed71..5f1d9144 100644 --- a/lib/middleware/rest.js +++ b/lib/middleware/rest.js @@ -2,7 +2,7 @@ * Module dependencies. */ -var asteroid = require('../asteroid'); +var loopback = require('../loopback'); var RemoteObjects = require('sl-remoting'); /** diff --git a/lib/models/application.js b/lib/models/application.js index a9664b13..4907a3b9 100644 --- a/lib/models/application.js +++ b/lib/models/application.js @@ -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); diff --git a/package.json b/package.json index 127cad16..3b8a071a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "asteroid", - "description": "asteroid", + "name": "loopback", + "description": "loopback", "version": "0.9.0", "scripts": { "test": "mocha -R spec" diff --git a/test/README.md b/test/README.md index 93dde894..241ae319 100644 --- a/test/README.md +++ b/test/README.md @@ -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'); ``` - -# asteroid - -## asteroid.createDataSource(options) + +# loopback + +## 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()); ``` - -## asteroid.remoteMethod(Model, fn, [options]); + +## 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'); diff --git a/test/app.test.js b/test/app.test.js index 72387eb9..a27748c4 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -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); diff --git a/test/data-source.test.js b/test/data-source.test.js index a62512b6..ae536d25 100644 --- a/test/data-source.test.js +++ b/test/data-source.test.js @@ -2,8 +2,8 @@ describe('DataSource', function() { var memory; beforeEach(function(){ - memory = asteroid.createDataSource({ - connector: asteroid.Memory + memory = loopback.createDataSource({ + connector: loopback.Memory }); }); diff --git a/test/geo-point.test.js b/test/geo-point.test.js index e794835e..223df816 100644 --- a/test/geo-point.test.js +++ b/test/geo-point.test.js @@ -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'} }); diff --git a/test/asteroid.test.js b/test/loopback.test.js similarity index 67% rename from test/asteroid.test.js rename to test/loopback.test.js index 232ad8b4..bedb0e1a 100644 --- a/test/asteroid.test.js +++ b/test/loopback.test.js @@ -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'}, diff --git a/test/model.test.js b/test/model.test.js index 44bad7cf..c8512b86 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -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', diff --git a/test/support.js b/test/support.js index e620f208..0919dca3 100644 --- a/test/support.js +++ b/test/support.js @@ -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) { From 1cf4338298d6896025b45522e7097521e9d1a731 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 16 Jul 2013 11:52:21 -0700 Subject: [PATCH 10/10] Rename jugglingdb to loopback-data --- index.js | 2 +- lib/application.js | 4 ++-- lib/connectors/memory.js | 2 +- lib/loopback.js | 4 ++-- lib/models/acl.js | 2 +- lib/models/application.js | 2 +- lib/models/installation.js | 2 +- lib/models/role.js | 2 +- package.json | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index e5802780..8594093e 100644 --- a/index.js +++ b/index.js @@ -15,4 +15,4 @@ loopback.Memory = require('./lib/connectors/memory'); * Types */ -loopback.GeoPoint = require('jugglingdb/lib/geo').GeoPoint; \ No newline at end of file +loopback.GeoPoint = require('loopback-data/lib/geo').GeoPoint; \ No newline at end of file diff --git a/lib/application.js b/lib/application.js index 390bc68d..4f8fa7f9 100644 --- a/lib/application.js +++ b/lib/application.js @@ -2,8 +2,8 @@ * Module dependencies. */ -var DataSource = require('jugglingdb').DataSource - , ModelBuilder = require('jugglingdb').ModelBuilder +var DataSource = require('loopback-data').DataSource + , ModelBuilder = require('loopback-data').ModelBuilder , assert = require('assert') , RemoteObjects = require('sl-remoting'); diff --git a/lib/connectors/memory.js b/lib/connectors/memory.js index ce027f27..3bfa4a75 100644 --- a/lib/connectors/memory.js +++ b/lib/connectors/memory.js @@ -13,7 +13,7 @@ var Connector = require('./base-connector') , util = require('util') , inherits = util.inherits , assert = require('assert') - , JdbMemory = require('jugglingdb/lib/adapters/memory'); + , JdbMemory = require('loopback-data/lib/adapters/memory'); /** * Create a new `Memory` connector with the given `options`. diff --git a/lib/loopback.js b/lib/loopback.js index c97a73d2..b0f0164b 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -8,8 +8,8 @@ var express = require('express') , path = require('path') , proto = require('./application') , utils = require('express/node_modules/connect').utils - , DataSource = require('jugglingdb').DataSource - , ModelBuilder = require('jugglingdb').ModelBuilder + , DataSource = require('loopback-data').DataSource + , ModelBuilder = require('loopback-data').ModelBuilder , assert = require('assert') , i8n = require('inflection'); diff --git a/lib/models/acl.js b/lib/models/acl.js index 9fe28310..7c70af43 100644 --- a/lib/models/acl.js +++ b/lib/models/acl.js @@ -45,7 +45,7 @@ var ACLSchema = { // readAccess, writeAccess --> public, userId, role module.exports = function(dataSource) { - dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + dataSource = dataSource || new require('loopback-data').ModelBuilder(); var ACL = dataSource.define('ACL', ACLSchema); return ACL; } \ No newline at end of file diff --git a/lib/models/application.js b/lib/models/application.js index 4907a3b9..e66e29da 100644 --- a/lib/models/application.js +++ b/lib/models/application.js @@ -89,7 +89,7 @@ function generateKey(hmacKey, algorithm) { } module.exports = function (dataSource) { - dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + dataSource = dataSource || new require('loopback-data').ModelBuilder(); // var AuthenticationScheme = dataSource.define('AuthenticationScheme', AuthenticationSchemeSchema); // ApplicationSchema.authenticationSchemes = [AuthenticationScheme]; diff --git a/lib/models/installation.js b/lib/models/installation.js index 28d8ee8d..d54b3246 100644 --- a/lib/models/installation.js +++ b/lib/models/installation.js @@ -20,7 +20,7 @@ var InstallationSchema = { }; module.exports = function(dataSource) { - dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + dataSource = dataSource || new require('loopback-data').ModelBuilder(); var Installation = dataSource.define('Installation', InstallationSchema); return Installation; } diff --git a/lib/models/role.js b/lib/models/role.js index 5259d8b3..810897e2 100644 --- a/lib/models/role.js +++ b/lib/models/role.js @@ -12,7 +12,7 @@ var RoleSchema = { } module.exports = function(dataSource) { - dataSource = dataSource || new require('jugglingdb').ModelBuilder(); + dataSource = dataSource || new require('loopback-data').ModelBuilder(); var Role = dataSource.define('Role', RoleSchema); return Role; } \ No newline at end of file diff --git a/package.json b/package.json index 3b8a071a..19add248 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dependencies": { "debug": "latest", "express": "~3.1.1", - "jugglingdb": "git+ssh://git@github.com:strongloop/jugglingdb.git", + "loopback-data": "git+ssh://git@github.com:strongloop/loopback-data.git", "sl-remoting": "git+ssh://git@github.com:strongloop/sl-remoting.git", "inflection": "~1.2.5" },