Dismantle `lib/models`.

- Move core models `Model` and `PersistedModel` to `lib/`.
 - Move `AccessContext` class to `lib/`, since it is not a model.
 - Move all other built-in models to `common/models`.

This is a preparation for extracting model definitions to JSON files.
By splitting the change into multiple commits, git is able to keep track
of file moves (renames).
This commit is contained in:
Miroslav Bajtoš 2014-10-09 17:32:03 +02:00
parent 3a0f793c9b
commit 1fe0110849
19 changed files with 54 additions and 69 deletions

View File

@ -2,7 +2,7 @@
* Module Dependencies. * Module Dependencies.
*/ */
var loopback = require('../loopback') var loopback = require('../../lib/loopback')
, assert = require('assert') , assert = require('assert')
, crypto = require('crypto') , crypto = require('crypto')
, uid = require('uid2') , uid = require('uid2')

View File

@ -31,12 +31,12 @@
*/ */
var loopback = require('../loopback'); var loopback = require('../../lib/loopback');
var async = require('async'); var async = require('async');
var assert = require('assert'); var assert = require('assert');
var debug = require('debug')('loopback:security:acl'); var debug = require('debug')('loopback:security:acl');
var ctx = require('./access-context'); var ctx = require('../../lib/access-context');
var AccessContext = ctx.AccessContext; var AccessContext = ctx.AccessContext;
var Principal = ctx.Principal; var Principal = ctx.Principal;
var AccessRequest = ctx.AccessRequest; var AccessRequest = ctx.AccessRequest;

View File

@ -1,4 +1,4 @@
var loopback = require('../loopback'); var loopback = require('../../lib/loopback');
var assert = require('assert'); var assert = require('assert');
// Authentication schemes // Authentication schemes

View File

@ -2,8 +2,8 @@
* Module Dependencies. * Module Dependencies.
*/ */
var PersistedModel = require('./persisted-model') var PersistedModel = require('../../lib/loopback').PersistedModel
, loopback = require('../loopback') , loopback = require('../../lib/loopback')
, crypto = require('crypto') , crypto = require('crypto')
, CJSON = {stringify: require('canonical-json')} , CJSON = {stringify: require('canonical-json')}
, async = require('async') , async = require('async')

View File

@ -2,8 +2,8 @@
* Module Dependencies. * Module Dependencies.
*/ */
var PersistedModel = require('../loopback').PersistedModel var PersistedModel = require('../../lib/loopback').PersistedModel
, loopback = require('../loopback') , loopback = require('../../lib/loopback')
, assert = require('assert'); , assert = require('assert');
/** /**

View File

@ -2,8 +2,8 @@
* Module Dependencies. * Module Dependencies.
*/ */
var Model = require('../loopback').Model var Model = require('../../lib/loopback').Model
, loopback = require('../loopback'); , loopback = require('../../lib/loopback');
var properties = { var properties = {
to: {type: String, required: true}, to: {type: String, required: true},

View File

@ -1,9 +1,9 @@
var loopback = require('../loopback'); var loopback = require('../../lib/loopback');
var debug = require('debug')('loopback:security:role'); var debug = require('debug')('loopback:security:role');
var assert = require('assert'); var assert = require('assert');
var async = require('async'); var async = require('async');
var AccessContext = require('./access-context').AccessContext; var AccessContext = require('../../lib/access-context').AccessContext;
// Role model // Role model
var RoleSchema = { var RoleSchema = {

View File

@ -2,8 +2,8 @@
* Module Dependencies. * Module Dependencies.
*/ */
var PersistedModel = require('../loopback').PersistedModel var PersistedModel = require('../../lib/loopback').PersistedModel
, loopback = require('../loopback') , loopback = require('../../lib/loopback')
, path = require('path') , path = require('path')
, SALT_WORK_FACTOR = 10 , SALT_WORK_FACTOR = 10
, crypto = require('crypto') , crypto = require('crypto')

View File

@ -6,21 +6,21 @@
"lib/runtime.js", "lib/runtime.js",
"lib/registry.js", "lib/registry.js",
{ "title": "Base models", "depth": 2 }, { "title": "Base models", "depth": 2 },
"lib/models/model.js", "lib/model.js",
"lib/models/persisted-model.js", "lib/persisted-model.js",
{ "title": "Middleware", "depth": 2 }, { "title": "Middleware", "depth": 2 },
"lib/middleware/rest.js", "lib/middleware/rest.js",
"lib/middleware/status.js", "lib/middleware/status.js",
"lib/middleware/token.js", "lib/middleware/token.js",
"lib/middleware/urlNotFound.js", "lib/middleware/urlNotFound.js",
{ "title": "Built-in models", "depth": 2 }, { "title": "Built-in models", "depth": 2 },
"lib/models/access-token.js", "common/models/access-token.js",
"lib/models/acl.js", "common/models/acl.js",
"lib/models/application.js", "common/models/application.js",
"lib/models/email.js", "common/models/email.js",
"lib/models/role.js", "common/models/role.js",
"lib/models/user.js", "common/models/user.js",
"lib/models/change.js" "common/models/change.js"
], ],
"assets": "/docs/assets" "assets": "/docs/assets"
} }

View File

@ -1,5 +1,5 @@
var loopback = require('../loopback'); var loopback = require('./loopback');
var AccessToken = require('./access-token'); var AccessToken = require('../common/models/access-token');
var debug = require('debug')('loopback:security:access-context'); var debug = require('debug')('loopback:security:access-context');
/** /**
@ -280,7 +280,7 @@ AccessRequest.prototype.exactlyMatches = function(acl) {
*/ */
AccessRequest.prototype.isAllowed = function() { AccessRequest.prototype.isAllowed = function() {
return this.permission !== require('./acl').ACL.DENY; return this.permission !== require('../common/models/acl').ACL.DENY;
} }
AccessRequest.prototype.debug = function() { AccessRequest.prototype.debug = function() {

View File

@ -1,13 +1,13 @@
module.exports = function(loopback) { module.exports = function(loopback) {
loopback.Email = require('./models/email'); loopback.Email = require('../common/models/email');
loopback.User = require('./models/user'); loopback.User = require('../common/models/user');
loopback.Application = require('./models/application'); loopback.Application = require('../common/models/application');
loopback.AccessToken = require('./models/access-token'); loopback.AccessToken = require('../common/models/access-token');
loopback.Role = require('./models/role').Role; loopback.Role = require('../common/models/role').Role;
loopback.RoleMapping = require('./models/role').RoleMapping; loopback.RoleMapping = require('../common/models/role').RoleMapping;
loopback.ACL = require('./models/acl').ACL; loopback.ACL = require('../common/models/acl').ACL;
loopback.Scope = require('./models/acl').Scope; loopback.Scope = require('../common/models/acl').Scope;
loopback.Change = require('./models/change'); loopback.Change = require('../common/models/change');
/*! /*!
* Automatically attach these models to dataSources * Automatically attach these models to dataSources

View File

@ -1,7 +1,7 @@
/*! /*!
* Module Dependencies. * Module Dependencies.
*/ */
var registry = require('../registry'); var registry = require('./registry');
var assert = require('assert'); var assert = require('assert');
var RemoteObjects = require('strong-remoting'); var RemoteObjects = require('strong-remoting');
var SharedClass = require('strong-remoting').SharedClass; var SharedClass = require('strong-remoting').SharedClass;
@ -250,7 +250,7 @@ Model._ACL = function getACL(ACL) {
if(_aclModel) { if(_aclModel) {
return _aclModel; return _aclModel;
} }
var aclModel = require('./acl').ACL; var aclModel = loopback.ACL;
_aclModel = registry.getModelByType(aclModel); _aclModel = registry.getModelByType(aclModel);
return _aclModel; return _aclModel;
}; };
@ -268,7 +268,7 @@ Model._ACL = function getACL(ACL) {
*/ */
Model.checkAccess = function(token, modelId, sharedMethod, ctx, callback) { Model.checkAccess = function(token, modelId, sharedMethod, ctx, callback) {
var ANONYMOUS = require('./access-token').ANONYMOUS; var ANONYMOUS = loopback.AccessToken.ANONYMOUS;
token = token || ANONYMOUS; token = token || ANONYMOUS;
var aclModel = Model._ACL(); var aclModel = Model._ACL();

View File

@ -1,12 +0,0 @@
exports.Model = require('./model');
exports.Email = require('./email');
exports.User = require('./user');
exports.AccessToken = require('./access-token');
exports.Application = require('./application');
exports.ACL = require('./acl');
exports.Role = require('./role');

View File

@ -3,7 +3,7 @@
*/ */
var Model = require('./model'); var Model = require('./model');
var runtime = require('../runtime'); var runtime = require('./runtime');
var assert = require('assert'); var assert = require('assert');
var async = require('async'); var async = require('async');
@ -960,7 +960,7 @@ PersistedModel.enableChangeTracking = function() {
} }
PersistedModel._defineChangeModel = function() { PersistedModel._defineChangeModel = function() {
var BaseChangeModel = require('./change'); var BaseChangeModel = require('./../common/models/change');
return this.Change = BaseChangeModel.extend(this.modelName + '-change', return this.Change = BaseChangeModel.extend(this.modelName + '-change',
{}, {},
{ {

View File

@ -371,8 +371,8 @@ registry.DataSource = DataSource;
* @private * @private
*/ */
registry.Model = require('./models/model'); registry.Model = require('./model');
registry.PersistedModel = require('./models/persisted-model'); registry.PersistedModel = require('./persisted-model');
// temporary alias to simplify migration of code based on <=2.0.0-beta3 // temporary alias to simplify migration of code based on <=2.0.0-beta3
Object.defineProperty(registry, 'DataModel', { Object.defineProperty(registry, 'DataModel', {

View File

@ -1,11 +1,9 @@
var assert = require('assert'); var assert = require('assert');
var loopback = require('../index'); var loopback = require('../index');
var acl = require('../lib/models/acl'); var Scope = loopback.Scope;
var Scope = acl.Scope; var ACL = loopback.ACL;
var ACL = acl.ACL; var Role = loopback.Role;
var role = require('../lib/models/role'); var RoleMapping = loopback.RoleMapping;
var Role = role.Role;
var RoleMapping = role.RoleMapping;
var User = loopback.User; var User = loopback.User;
var testModel; var testModel;

View File

@ -2,7 +2,7 @@ var async = require('async');
var loopback = require('../'); var loopback = require('../');
// create a unique Checkpoint model // create a unique Checkpoint model
var Checkpoint = require('../lib/models/checkpoint').extend('TestCheckpoint'); var Checkpoint = require('../common/models/checkpoint').extend('TestCheckpoint');
Checkpoint.attachTo(loopback.memory()); Checkpoint.attachTo(loopback.memory());
describe('Checkpoint', function() { describe('Checkpoint', function() {

View File

@ -1,10 +1,9 @@
var assert = require('assert'); var assert = require('assert');
var loopback = require('../index'); var loopback = require('../index');
var role = require('../lib/models/role'); var Role = loopback.Role;
var Role = role.Role; var RoleMapping = loopback.RoleMapping;
var RoleMapping = role.RoleMapping;
var User = loopback.User; var User = loopback.User;
var ACL = require('../lib/models/acl'); var ACL = loopback.ACL;
function checkResult(err, result) { function checkResult(err, result) {
// console.log(err, result); // console.log(err, result);