Rename DataModel to PersistedModel
This commit is contained in:
parent
93a74f2821
commit
ea5b9d16fc
|
@ -1,6 +1,6 @@
|
|||
var loopback = require('../../');
|
||||
|
||||
var CartItem = exports.CartItem = loopback.DataModel.extend('CartItem', {
|
||||
var CartItem = exports.CartItem = loopback.PersistedModel.extend('CartItem', {
|
||||
tax: {type: Number, default: 0.1},
|
||||
price: Number,
|
||||
item: String,
|
||||
|
|
|
@ -178,10 +178,22 @@ loopback.createModel = function (name, properties, options) {
|
|||
var BaseModel = options.base || options.super;
|
||||
|
||||
if(typeof BaseModel === 'string') {
|
||||
var baseName = BaseModel;
|
||||
BaseModel = loopback.getModel(BaseModel);
|
||||
|
||||
if (BaseModel === undefined) {
|
||||
if (baseName === 'DataModel') {
|
||||
console.warn('Model `%s` is extending deprecated `DataModel. ' +
|
||||
'Use `PeristedModel` instead.', name);
|
||||
BaseModel = loopback.PersistedModel;
|
||||
} else {
|
||||
console.warn('Model `%s` is extending an unknown model `%s`. ' +
|
||||
'Using `PersistedModel` as the base.', name, baseName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BaseModel = BaseModel || loopback.DataModel;
|
||||
BaseModel = BaseModel || loopback.PersistedModel;
|
||||
|
||||
var model = BaseModel.extend(name, properties, options);
|
||||
|
||||
|
@ -337,7 +349,20 @@ loopback.autoAttachModel = function(ModelCtor) {
|
|||
*/
|
||||
|
||||
loopback.Model = require('./models/model');
|
||||
loopback.DataModel = require('./models/data-model');
|
||||
loopback.PersistedModel = require('./models/persisted-model');
|
||||
|
||||
// temporary alias to simplify migration of code based on <=2.0.0-beta3
|
||||
Object.defineProperty(loopback, 'DataModel', {
|
||||
get: function() {
|
||||
var stackLines = new Error().stack.split('\n');
|
||||
console.warn('loopback.DataModel is deprecated, ' +
|
||||
'use loopback.PersistedModel instead.');
|
||||
// Log the location where loopback.DataModel was called
|
||||
console.warn(stackLines[2]);
|
||||
return loopback.PersistedModel;
|
||||
}
|
||||
});
|
||||
|
||||
loopback.Email = require('./models/email');
|
||||
loopback.User = require('./models/user');
|
||||
loopback.Application = require('./models/application');
|
||||
|
@ -358,7 +383,7 @@ var dataSourceTypes = {
|
|||
};
|
||||
|
||||
loopback.Email.autoAttach = dataSourceTypes.MAIL;
|
||||
loopback.DataModel.autoAttach = dataSourceTypes.DB;
|
||||
loopback.PersistedModel.autoAttach = dataSourceTypes.DB;
|
||||
loopback.User.autoAttach = dataSourceTypes.DB;
|
||||
loopback.AccessToken.autoAttach = dataSourceTypes.DB;
|
||||
loopback.Role.autoAttach = dataSourceTypes.DB;
|
||||
|
|
|
@ -91,7 +91,7 @@ var ACLSchema = {
|
|||
* @inherits Model
|
||||
*/
|
||||
|
||||
var ACL = loopback.DataModel.extend('ACL', ACLSchema);
|
||||
var ACL = loopback.PersistedModel.extend('ACL', ACLSchema);
|
||||
|
||||
ACL.ALL = AccessContext.ALL;
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ function generateKey(hmacKey, algorithm, encoding) {
|
|||
* @inherits {Model}
|
||||
*/
|
||||
|
||||
var Application = loopback.DataModel.extend('Application', ApplicationSchema);
|
||||
var Application = loopback.PersistedModel.extend('Application', ApplicationSchema);
|
||||
|
||||
/*!
|
||||
* A hook to generate keys before creation
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Module Dependencies.
|
||||
*/
|
||||
|
||||
var DataModel = require('./data-model')
|
||||
var PersistedModel = require('./persisted-model')
|
||||
, loopback = require('../loopback')
|
||||
, crypto = require('crypto')
|
||||
, CJSON = {stringify: require('canonical-json')}
|
||||
|
@ -45,7 +45,7 @@ var options = {
|
|||
* @inherits {Model}
|
||||
*/
|
||||
|
||||
var Change = module.exports = DataModel.extend('Change', properties, options);
|
||||
var Change = module.exports = PersistedModel.extend('Change', properties, options);
|
||||
|
||||
/*!
|
||||
* Constants
|
||||
|
@ -67,7 +67,7 @@ Change.Conflict = Conflict;
|
|||
*/
|
||||
|
||||
Change.setup = function() {
|
||||
DataModel.setup.call(this);
|
||||
PersistedModel.setup.call(this);
|
||||
var Change = this;
|
||||
|
||||
Change.getter.id = function() {
|
||||
|
@ -497,8 +497,8 @@ Change.prototype.getModel = function(callback) {
|
|||
* **Note: call `conflict.fetch()` to get the `target` and `source` models.
|
||||
*
|
||||
* @param {*} modelId
|
||||
* @param {DataModel} SourceModel
|
||||
* @param {DataModel} TargetModel
|
||||
* @param {PersistedModel} SourceModel
|
||||
* @param {PersistedModel} TargetModel
|
||||
* @property {ModelClass} source The source model instance
|
||||
* @property {ModelClass} target The target model instance
|
||||
*/
|
||||
|
@ -516,8 +516,8 @@ function Conflict(modelId, SourceModel, TargetModel) {
|
|||
*
|
||||
* @callback {Function} callback
|
||||
* @param {Error}
|
||||
* @param {DataModel} source
|
||||
* @param {DataModel} target
|
||||
* @param {PersistedModel} source
|
||||
* @param {PersistedModel} target
|
||||
*/
|
||||
|
||||
Conflict.prototype.models = function(cb) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Module Dependencies.
|
||||
*/
|
||||
|
||||
var DataModel = require('../loopback').DataModel
|
||||
var PersistedModel = require('../loopback').PersistedModel
|
||||
, loopback = require('../loopback')
|
||||
, assert = require('assert');
|
||||
|
||||
|
@ -32,10 +32,10 @@ var options = {
|
|||
* @property sourceId {String} the source identifier
|
||||
*
|
||||
* @class
|
||||
* @inherits {DataModel}
|
||||
* @inherits {PersistedModel}
|
||||
*/
|
||||
|
||||
var Checkpoint = module.exports = DataModel.extend('Checkpoint', properties, options);
|
||||
var Checkpoint = module.exports = PersistedModel.extend('Checkpoint', properties, options);
|
||||
|
||||
/**
|
||||
* Get the current checkpoint id
|
||||
|
|
|
@ -16,43 +16,43 @@ var async = require('async');
|
|||
* Listen for model changes using the `change` event.
|
||||
*
|
||||
* ```js
|
||||
* MyDataModel.on('changed', function(obj) {
|
||||
* MyPersistedModel.on('changed', function(obj) {
|
||||
* console.log(obj) // => the changed model
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @class DataModel
|
||||
* @class PersistedModel
|
||||
* @param {Object} data
|
||||
* @param {Number} data.id The default id property
|
||||
*/
|
||||
|
||||
var DataModel = module.exports = Model.extend('DataModel');
|
||||
var PersistedModel = module.exports = Model.extend('PersistedModel');
|
||||
|
||||
/*!
|
||||
* Setup the `DataModel` constructor.
|
||||
* Setup the `PersistedModel` constructor.
|
||||
*/
|
||||
|
||||
DataModel.setup = function setupDataModel() {
|
||||
PersistedModel.setup = function setupPersistedModel() {
|
||||
// call Model.setup first
|
||||
Model.setup.call(this);
|
||||
|
||||
var DataModel = this;
|
||||
var PersistedModel = this;
|
||||
var typeName = this.modelName;
|
||||
|
||||
// setup a remoting type converter for this model
|
||||
RemoteObjects.convert(typeName, function(val) {
|
||||
return val ? new DataModel(val) : val;
|
||||
return val ? new PersistedModel(val) : val;
|
||||
});
|
||||
|
||||
// enable change tracking (usually for replication)
|
||||
if(this.settings.trackChanges) {
|
||||
DataModel._defineChangeModel();
|
||||
DataModel.once('dataSourceAttached', function() {
|
||||
DataModel.enableChangeTracking();
|
||||
PersistedModel._defineChangeModel();
|
||||
PersistedModel.once('dataSourceAttached', function() {
|
||||
PersistedModel.enableChangeTracking();
|
||||
});
|
||||
}
|
||||
|
||||
DataModel.setupRemoting();
|
||||
PersistedModel.setupRemoting();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -63,7 +63,7 @@ function throwNotAttached(modelName, methodName) {
|
|||
throw new Error(
|
||||
'Cannot call ' + modelName + '.'+ methodName + '().'
|
||||
+ ' The ' + methodName + ' method has not been setup.'
|
||||
+ ' The DataModel has not been correctly attached to a DataSource!'
|
||||
+ ' The PersistedModel has not been correctly attached to a DataSource!'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ function convertNullToNotFoundError(ctx, cb) {
|
|||
* - instance (null or Model)
|
||||
*/
|
||||
|
||||
DataModel.create = function (data, callback) {
|
||||
PersistedModel.create = function (data, callback) {
|
||||
throwNotAttached(this.modelName, 'create');
|
||||
};
|
||||
|
||||
|
@ -105,7 +105,7 @@ DataModel.create = function (data, callback) {
|
|||
* @param {Function} [callback] The callback function
|
||||
*/
|
||||
|
||||
DataModel.upsert = DataModel.updateOrCreate = function upsert(data, callback) {
|
||||
PersistedModel.upsert = PersistedModel.updateOrCreate = function upsert(data, callback) {
|
||||
throwNotAttached(this.modelName, 'upsert');
|
||||
};
|
||||
|
||||
|
@ -118,7 +118,7 @@ DataModel.upsert = DataModel.updateOrCreate = function upsert(data, callback) {
|
|||
* @param {Function} cb - callback called with (err, instance)
|
||||
*/
|
||||
|
||||
DataModel.findOrCreate = function findOrCreate(query, data, callback) {
|
||||
PersistedModel.findOrCreate = function findOrCreate(query, data, callback) {
|
||||
throwNotAttached(this.modelName, 'findOrCreate');
|
||||
};
|
||||
|
||||
|
@ -129,7 +129,7 @@ DataModel.findOrCreate = function findOrCreate(query, data, callback) {
|
|||
* @param {Function} cb - callbacl called with (err, exists: Bool)
|
||||
*/
|
||||
|
||||
DataModel.exists = function exists(id, cb) {
|
||||
PersistedModel.exists = function exists(id, cb) {
|
||||
throwNotAttached(this.modelName, 'exists');
|
||||
};
|
||||
|
||||
|
@ -140,7 +140,7 @@ DataModel.exists = function exists(id, cb) {
|
|||
* @param {Function} cb - callback called with (err, instance)
|
||||
*/
|
||||
|
||||
DataModel.findById = function find(id, cb) {
|
||||
PersistedModel.findById = function find(id, cb) {
|
||||
throwNotAttached(this.modelName, 'findById');
|
||||
};
|
||||
|
||||
|
@ -151,7 +151,7 @@ DataModel.findById = function find(id, cb) {
|
|||
* @param {Object} params (optional)
|
||||
*
|
||||
* - where: Object `{ key: val, key2: {gt: 'val2'}}`
|
||||
* - include: String, Object or Array. See DataModel.include documentation.
|
||||
* - include: String, Object or Array. See PersistedModel.include documentation.
|
||||
* - order: String
|
||||
* - limit: Number
|
||||
* - skip: Number
|
||||
|
@ -162,7 +162,7 @@ DataModel.findById = function find(id, cb) {
|
|||
* - Array of instances
|
||||
*/
|
||||
|
||||
DataModel.find = function find(params, cb) {
|
||||
PersistedModel.find = function find(params, cb) {
|
||||
throwNotAttached(this.modelName, 'find');
|
||||
};
|
||||
|
||||
|
@ -173,7 +173,7 @@ DataModel.find = function find(params, cb) {
|
|||
* @param {Function} cb - callback called with (err, instance)
|
||||
*/
|
||||
|
||||
DataModel.findOne = function findOne(params, cb) {
|
||||
PersistedModel.findOne = function findOne(params, cb) {
|
||||
throwNotAttached(this.modelName, 'findOne');
|
||||
};
|
||||
|
||||
|
@ -183,9 +183,9 @@ DataModel.findOne = function findOne(params, cb) {
|
|||
* @param {Function} [cb] - callback called with (err)
|
||||
*/
|
||||
|
||||
DataModel.remove =
|
||||
DataModel.deleteAll =
|
||||
DataModel.destroyAll = function destroyAll(where, cb) {
|
||||
PersistedModel.remove =
|
||||
PersistedModel.deleteAll =
|
||||
PersistedModel.destroyAll = function destroyAll(where, cb) {
|
||||
throwNotAttached(this.modelName, 'destroyAll');
|
||||
};
|
||||
|
||||
|
@ -195,9 +195,9 @@ DataModel.destroyAll = function destroyAll(where, cb) {
|
|||
* @param {Function} cb - callback called with (err)
|
||||
*/
|
||||
|
||||
DataModel.removeById =
|
||||
DataModel.deleteById =
|
||||
DataModel.destroyById = function deleteById(id, cb) {
|
||||
PersistedModel.removeById =
|
||||
PersistedModel.deleteById =
|
||||
PersistedModel.destroyById = function deleteById(id, cb) {
|
||||
throwNotAttached(this.modelName, 'deleteById');
|
||||
};
|
||||
|
||||
|
@ -208,7 +208,7 @@ DataModel.destroyById = function deleteById(id, cb) {
|
|||
* @param {Function} cb - callback, called with (err, count)
|
||||
*/
|
||||
|
||||
DataModel.count = function (where, cb) {
|
||||
PersistedModel.count = function (where, cb) {
|
||||
throwNotAttached(this.modelName, 'count');
|
||||
};
|
||||
|
||||
|
@ -219,7 +219,7 @@ DataModel.count = function (where, cb) {
|
|||
* @param callback(err, obj)
|
||||
*/
|
||||
|
||||
DataModel.prototype.save = function (options, callback) {
|
||||
PersistedModel.prototype.save = function (options, callback) {
|
||||
var Model = this.constructor;
|
||||
|
||||
if (typeof options == 'function') {
|
||||
|
@ -286,7 +286,7 @@ DataModel.prototype.save = function (options, callback) {
|
|||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
DataModel.prototype.isNewRecord = function () {
|
||||
PersistedModel.prototype.isNewRecord = function () {
|
||||
throwNotAttached(this.constructor.modelName, 'isNewRecord');
|
||||
};
|
||||
|
||||
|
@ -296,13 +296,13 @@ DataModel.prototype.isNewRecord = function () {
|
|||
* @triggers `destroy` hook (async) before and after destroying object
|
||||
*/
|
||||
|
||||
DataModel.prototype.remove =
|
||||
DataModel.prototype.delete =
|
||||
DataModel.prototype.destroy = function (cb) {
|
||||
PersistedModel.prototype.remove =
|
||||
PersistedModel.prototype.delete =
|
||||
PersistedModel.prototype.destroy = function (cb) {
|
||||
throwNotAttached(this.constructor.modelName, 'destroy');
|
||||
};
|
||||
|
||||
DataModel.prototype.destroy._delegate = true;
|
||||
PersistedModel.prototype.destroy._delegate = true;
|
||||
|
||||
/**
|
||||
* Update single attribute
|
||||
|
@ -314,7 +314,7 @@ DataModel.prototype.destroy._delegate = true;
|
|||
* @param {Function} callback - callback called with (err, instance)
|
||||
*/
|
||||
|
||||
DataModel.prototype.updateAttribute = function updateAttribute(name, value, callback) {
|
||||
PersistedModel.prototype.updateAttribute = function updateAttribute(name, value, callback) {
|
||||
throwNotAttached(this.constructor.modelName, 'updateAttribute');
|
||||
};
|
||||
|
||||
|
@ -328,7 +328,7 @@ DataModel.prototype.updateAttribute = function updateAttribute(name, value, call
|
|||
* @param {Function} callback - callback called with (err, instance)
|
||||
*/
|
||||
|
||||
DataModel.prototype.updateAttributes = function updateAttributes(data, cb) {
|
||||
PersistedModel.prototype.updateAttributes = function updateAttributes(data, cb) {
|
||||
throwNotAttached(this.modelName, 'updateAttributes');
|
||||
};
|
||||
|
||||
|
@ -339,12 +339,12 @@ DataModel.prototype.updateAttributes = function updateAttributes(data, cb) {
|
|||
* @param {Function} callback - called with (err, instance) arguments
|
||||
*/
|
||||
|
||||
DataModel.prototype.reload = function reload(callback) {
|
||||
PersistedModel.prototype.reload = function reload(callback) {
|
||||
throwNotAttached(this.constructor.modelName, 'reload');
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the correct `id` property for the `DataModel`. If a `Connector` defines
|
||||
* Set the correct `id` property for the `PersistedModel`. If a `Connector` defines
|
||||
* a `setId` method it will be used. Otherwise the default lookup is used. You
|
||||
* should override this method to handle complex ids.
|
||||
*
|
||||
|
@ -352,18 +352,18 @@ DataModel.prototype.reload = function reload(callback) {
|
|||
* specifies.
|
||||
*/
|
||||
|
||||
DataModel.prototype.setId = function(val) {
|
||||
PersistedModel.prototype.setId = function(val) {
|
||||
var ds = this.getDataSource();
|
||||
this[this.getIdName()] = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the `id` value for the `DataModel`.
|
||||
* Get the `id` value for the `PersistedModel`.
|
||||
*
|
||||
* @returns {*} The `id` value
|
||||
*/
|
||||
|
||||
DataModel.prototype.getId = function() {
|
||||
PersistedModel.prototype.getId = function() {
|
||||
var data = this.toObject();
|
||||
if(!data) return;
|
||||
return data[this.getIdName()];
|
||||
|
@ -375,7 +375,7 @@ DataModel.prototype.getId = function() {
|
|||
* @returns {String} The `id` property name
|
||||
*/
|
||||
|
||||
DataModel.prototype.getIdName = function() {
|
||||
PersistedModel.prototype.getIdName = function() {
|
||||
return this.constructor.getIdName();
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ DataModel.prototype.getIdName = function() {
|
|||
* @returns {String} The `id` property name
|
||||
*/
|
||||
|
||||
DataModel.getIdName = function() {
|
||||
PersistedModel.getIdName = function() {
|
||||
var Model = this;
|
||||
var ds = Model.getDataSource();
|
||||
|
||||
|
@ -396,40 +396,40 @@ DataModel.getIdName = function() {
|
|||
}
|
||||
}
|
||||
|
||||
DataModel.setupRemoting = function() {
|
||||
var DataModel = this;
|
||||
var typeName = DataModel.modelName;
|
||||
var options = DataModel.settings;
|
||||
PersistedModel.setupRemoting = function() {
|
||||
var PersistedModel = this;
|
||||
var typeName = PersistedModel.modelName;
|
||||
var options = PersistedModel.settings;
|
||||
|
||||
function setRemoting(scope, name, options) {
|
||||
var fn = scope[name];
|
||||
fn._delegate = true;
|
||||
options.isStatic = scope === DataModel;
|
||||
DataModel.remoteMethod(name, options);
|
||||
options.isStatic = scope === PersistedModel;
|
||||
PersistedModel.remoteMethod(name, options);
|
||||
}
|
||||
|
||||
setRemoting(DataModel, 'create', {
|
||||
setRemoting(PersistedModel, 'create', {
|
||||
description: 'Create a new instance of the model and persist it into the data source',
|
||||
accepts: {arg: 'data', type: 'object', description: 'Model instance data', http: {source: 'body'}},
|
||||
returns: {arg: 'data', type: typeName, root: true},
|
||||
http: {verb: 'post', path: '/'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'upsert', {
|
||||
setRemoting(PersistedModel, 'upsert', {
|
||||
description: 'Update an existing model instance or insert a new one into the data source',
|
||||
accepts: {arg: 'data', type: 'object', description: 'Model instance data', http: {source: 'body'}},
|
||||
returns: {arg: 'data', type: typeName, root: true},
|
||||
http: {verb: 'put', path: '/'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'exists', {
|
||||
setRemoting(PersistedModel, 'exists', {
|
||||
description: 'Check whether a model instance exists in the data source',
|
||||
accepts: {arg: 'id', type: 'any', description: 'Model id', required: true},
|
||||
returns: {arg: 'exists', type: 'boolean'},
|
||||
http: {verb: 'get', path: '/:id/exists'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'findById', {
|
||||
setRemoting(PersistedModel, 'findById', {
|
||||
description: 'Find a model instance by id from the data source',
|
||||
accepts: {
|
||||
arg: 'id', type: 'any', description: 'Model id', required: true,
|
||||
|
@ -440,42 +440,42 @@ DataModel.setupRemoting = function() {
|
|||
rest: {after: convertNullToNotFoundError}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'find', {
|
||||
setRemoting(PersistedModel, 'find', {
|
||||
description: 'Find all instances of the model matched by filter from the data source',
|
||||
accepts: {arg: 'filter', type: 'object', description: 'Filter defining fields, where, orderBy, offset, and limit'},
|
||||
returns: {arg: 'data', type: [typeName], root: true},
|
||||
http: {verb: 'get', path: '/'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'findOne', {
|
||||
setRemoting(PersistedModel, 'findOne', {
|
||||
description: 'Find first instance of the model matched by filter from the data source',
|
||||
accepts: {arg: 'filter', type: 'object', description: 'Filter defining fields, where, orderBy, offset, and limit'},
|
||||
returns: {arg: 'data', type: typeName, root: true},
|
||||
http: {verb: 'get', path: '/findOne'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'destroyAll', {
|
||||
setRemoting(PersistedModel, 'destroyAll', {
|
||||
description: 'Delete all matching records',
|
||||
accepts: {arg: 'where', type: 'object', description: 'filter.where object'},
|
||||
http: {verb: 'del', path: '/'},
|
||||
shared: false
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'removeById', {
|
||||
setRemoting(PersistedModel, 'removeById', {
|
||||
description: 'Delete a model instance by id from the data source',
|
||||
accepts: {arg: 'id', type: 'any', description: 'Model id', required: true,
|
||||
http: {source: 'path'}},
|
||||
http: {verb: 'del', path: '/:id'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'count', {
|
||||
setRemoting(PersistedModel, 'count', {
|
||||
description: 'Count instances of the model matched by where from the data source',
|
||||
accepts: {arg: 'where', type: 'object', description: 'Criteria to match model instances'},
|
||||
returns: {arg: 'count', type: 'number'},
|
||||
http: {verb: 'get', path: '/count'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel.prototype, 'updateAttributes', {
|
||||
setRemoting(PersistedModel.prototype, 'updateAttributes', {
|
||||
description: 'Update attributes for a model instance and persist it into the data source',
|
||||
accepts: {arg: 'data', type: 'object', http: {source: 'body'}, description: 'An object of model property name/value pairs'},
|
||||
returns: {arg: 'data', type: typeName, root: true},
|
||||
|
@ -483,7 +483,7 @@ DataModel.setupRemoting = function() {
|
|||
});
|
||||
|
||||
if(options.trackChanges) {
|
||||
setRemoting(DataModel, 'diff', {
|
||||
setRemoting(PersistedModel, 'diff', {
|
||||
description: 'Get a set of deltas and conflicts since the given checkpoint',
|
||||
accepts: [
|
||||
{arg: 'since', type: 'number', description: 'Find deltas since this checkpoint'},
|
||||
|
@ -494,7 +494,7 @@ DataModel.setupRemoting = function() {
|
|||
http: {verb: 'post', path: '/diff'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'changes', {
|
||||
setRemoting(PersistedModel, 'changes', {
|
||||
description: 'Get the changes to a model since a given checkpoint.'
|
||||
+ 'Provide a filter object to reduce the number of results returned.',
|
||||
accepts: [
|
||||
|
@ -505,37 +505,37 @@ DataModel.setupRemoting = function() {
|
|||
http: {verb: 'get', path: '/changes'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'checkpoint', {
|
||||
setRemoting(PersistedModel, 'checkpoint', {
|
||||
description: 'Create a checkpoint.',
|
||||
returns: {arg: 'checkpoint', type: 'object', root: true},
|
||||
http: {verb: 'post', path: '/checkpoint'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'currentCheckpoint', {
|
||||
setRemoting(PersistedModel, 'currentCheckpoint', {
|
||||
description: 'Get the current checkpoint.',
|
||||
returns: {arg: 'checkpoint', type: 'object', root: true},
|
||||
http: {verb: 'get', path: '/checkpoint'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'createUpdates', {
|
||||
setRemoting(PersistedModel, 'createUpdates', {
|
||||
description: 'Create an update list from a delta list',
|
||||
accepts: {arg: 'deltas', type: 'array', http: {source: 'body'}},
|
||||
returns: {arg: 'updates', type: 'array', root: true},
|
||||
http: {verb: 'post', path: '/create-updates'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'bulkUpdate', {
|
||||
setRemoting(PersistedModel, 'bulkUpdate', {
|
||||
description: 'Run multiple updates at once. Note: this is not atomic.',
|
||||
accepts: {arg: 'updates', type: 'array'},
|
||||
http: {verb: 'post', path: '/bulk-update'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'rectifyAllChanges', {
|
||||
setRemoting(PersistedModel, 'rectifyAllChanges', {
|
||||
description: 'Rectify all Model changes.',
|
||||
http: {verb: 'post', path: '/rectify-all'}
|
||||
});
|
||||
|
||||
setRemoting(DataModel, 'rectifyChange', {
|
||||
setRemoting(PersistedModel, 'rectifyChange', {
|
||||
description: 'Tell loopback that a change to the model with the given id has occurred.',
|
||||
accepts: {arg: 'id', type: 'any', http: {source: 'path'}},
|
||||
http: {verb: 'post', path: '/:id/rectify-change'}
|
||||
|
@ -553,7 +553,7 @@ DataModel.setupRemoting = function() {
|
|||
* @param {Function} callback
|
||||
*/
|
||||
|
||||
DataModel.diff = function(since, remoteChanges, callback) {
|
||||
PersistedModel.diff = function(since, remoteChanges, callback) {
|
||||
var Change = this.getChangeModel();
|
||||
Change.diff(this.modelName, since, remoteChanges, callback);
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ DataModel.diff = function(since, remoteChanges, callback) {
|
|||
* @end
|
||||
*/
|
||||
|
||||
DataModel.changes = function(since, filter, callback) {
|
||||
PersistedModel.changes = function(since, filter, callback) {
|
||||
if(typeof since === 'function') {
|
||||
filter = {};
|
||||
callback = since;
|
||||
|
@ -620,7 +620,7 @@ DataModel.changes = function(since, filter, callback) {
|
|||
* @param {Function} callback
|
||||
*/
|
||||
|
||||
DataModel.checkpoint = function(cb) {
|
||||
PersistedModel.checkpoint = function(cb) {
|
||||
var Checkpoint = this.getChangeModel().getCheckpointModel();
|
||||
this.getSourceId(function(err, sourceId) {
|
||||
if(err) return cb(err);
|
||||
|
@ -639,7 +639,7 @@ DataModel.checkpoint = function(cb) {
|
|||
* @end
|
||||
*/
|
||||
|
||||
DataModel.currentCheckpoint = function(cb) {
|
||||
PersistedModel.currentCheckpoint = function(cb) {
|
||||
var Checkpoint = this.getChangeModel().getCheckpointModel();
|
||||
Checkpoint.current(cb);
|
||||
}
|
||||
|
@ -657,7 +657,7 @@ DataModel.currentCheckpoint = function(cb) {
|
|||
* due to conflicts.
|
||||
*/
|
||||
|
||||
DataModel.replicate = function(since, targetModel, options, callback) {
|
||||
PersistedModel.replicate = function(since, targetModel, options, callback) {
|
||||
var lastArg = arguments[arguments.length - 1];
|
||||
|
||||
if(typeof lastArg === 'function' && arguments.length > 1) {
|
||||
|
@ -750,7 +750,7 @@ DataModel.replicate = function(since, targetModel, options, callback) {
|
|||
* @param {Function} callback
|
||||
*/
|
||||
|
||||
DataModel.createUpdates = function(deltas, cb) {
|
||||
PersistedModel.createUpdates = function(deltas, cb) {
|
||||
var Change = this.getChangeModel();
|
||||
var updates = [];
|
||||
var Model = this;
|
||||
|
@ -802,7 +802,7 @@ DataModel.createUpdates = function(deltas, cb) {
|
|||
* @param {Function} callback
|
||||
*/
|
||||
|
||||
DataModel.bulkUpdate = function(updates, callback) {
|
||||
PersistedModel.bulkUpdate = function(updates, callback) {
|
||||
var tasks = [];
|
||||
var Model = this;
|
||||
var idName = this.dataSource.idName(this.modelName);
|
||||
|
@ -838,7 +838,7 @@ DataModel.bulkUpdate = function(updates, callback) {
|
|||
* @return {Change}
|
||||
*/
|
||||
|
||||
DataModel.getChangeModel = function() {
|
||||
PersistedModel.getChangeModel = function() {
|
||||
var changeModel = this.Change;
|
||||
var isSetup = changeModel && changeModel.dataSource;
|
||||
|
||||
|
@ -855,7 +855,7 @@ DataModel.getChangeModel = function() {
|
|||
* @param {String} sourceId
|
||||
*/
|
||||
|
||||
DataModel.getSourceId = function(cb) {
|
||||
PersistedModel.getSourceId = function(cb) {
|
||||
var dataSource = this.dataSource;
|
||||
if(!dataSource) {
|
||||
this.once('dataSourceAttached', this.getSourceId.bind(this, cb));
|
||||
|
@ -872,7 +872,7 @@ DataModel.getSourceId = function(cb) {
|
|||
* Enable the tracking of changes made to the model. Usually for replication.
|
||||
*/
|
||||
|
||||
DataModel.enableChangeTracking = function() {
|
||||
PersistedModel.enableChangeTracking = function() {
|
||||
var Model = this;
|
||||
var Change = this.Change || this._defineChangeModel();
|
||||
var cleanupInterval = Model.settings.changeCleanupInterval || 30000;
|
||||
|
@ -911,7 +911,7 @@ DataModel.enableChangeTracking = function() {
|
|||
}
|
||||
}
|
||||
|
||||
DataModel._defineChangeModel = function() {
|
||||
PersistedModel._defineChangeModel = function() {
|
||||
var BaseChangeModel = require('./change');
|
||||
return this.Change = BaseChangeModel.extend(this.modelName + '-change',
|
||||
{},
|
||||
|
@ -921,7 +921,7 @@ DataModel._defineChangeModel = function() {
|
|||
);
|
||||
}
|
||||
|
||||
DataModel.rectifyAllChanges = function(callback) {
|
||||
PersistedModel.rectifyAllChanges = function(callback) {
|
||||
this.getChangeModel().rectifyAll(callback);
|
||||
}
|
||||
|
||||
|
@ -932,7 +932,7 @@ DataModel.rectifyAllChanges = function(callback) {
|
|||
* @param {Error} err
|
||||
*/
|
||||
|
||||
DataModel.handleChangeError = function(err) {
|
||||
PersistedModel.handleChangeError = function(err) {
|
||||
if(err) {
|
||||
console.error(Model.modelName + ' Change Tracking Error:');
|
||||
console.error(err);
|
||||
|
@ -947,9 +947,9 @@ DataModel.handleChangeError = function(err) {
|
|||
* @param {Error} err
|
||||
*/
|
||||
|
||||
DataModel.rectifyChange = function(id, callback) {
|
||||
PersistedModel.rectifyChange = function(id, callback) {
|
||||
var Change = this.getChangeModel();
|
||||
Change.rectifyModelChanges(this.modelName, [id], callback);
|
||||
}
|
||||
|
||||
DataModel.setup();
|
||||
PersistedModel.setup();
|
|
@ -2,7 +2,7 @@
|
|||
* Module Dependencies.
|
||||
*/
|
||||
|
||||
var DataModel = require('../loopback').DataModel
|
||||
var PersistedModel = require('../loopback').PersistedModel
|
||||
, loopback = require('../loopback')
|
||||
, path = require('path')
|
||||
, SALT_WORK_FACTOR = 10
|
||||
|
@ -126,7 +126,7 @@ var options = {
|
|||
* @inherits {Model}
|
||||
*/
|
||||
|
||||
var User = module.exports = DataModel.extend('User', properties, options);
|
||||
var User = module.exports = PersistedModel.extend('User', properties, options);
|
||||
|
||||
/**
|
||||
* Login a user by with the given `credentials`.
|
||||
|
@ -415,7 +415,7 @@ User.resetPassword = function(options, cb) {
|
|||
|
||||
User.setup = function () {
|
||||
// We need to call the base class's setup method
|
||||
DataModel.setup.call(this);
|
||||
PersistedModel.setup.call(this);
|
||||
var UserModel = this;
|
||||
|
||||
// max ttl
|
||||
|
|
|
@ -125,7 +125,7 @@ function createTestApp(testToken, done) {
|
|||
app.use(loopback.rest());
|
||||
app.enableAuth();
|
||||
|
||||
var TestModel = loopback.DataModel.extend('test', {}, {
|
||||
var TestModel = loopback.PersistedModel.extend('test', {}, {
|
||||
acls: [
|
||||
{
|
||||
principalType: "ROLE",
|
||||
|
|
|
@ -22,7 +22,7 @@ before(function() {
|
|||
describe('security scopes', function () {
|
||||
beforeEach(function() {
|
||||
var ds = this.ds = loopback.createDataSource({connector: loopback.Memory});
|
||||
testModel = loopback.DataModel.extend('testModel');
|
||||
testModel = loopback.PersistedModel.extend('testModel');
|
||||
ACL.attachTo(ds);
|
||||
Role.attachTo(ds);
|
||||
RoleMapping.attachTo(ds);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var path = require('path');
|
||||
var SIMPLE_APP = path.join(__dirname, 'fixtures', 'simple-app');
|
||||
var loopback = require('../');
|
||||
var DataModel = loopback.DataModel;
|
||||
var PersistedModel = loopback.PersistedModel;
|
||||
|
||||
var describe = require('./util/describe');
|
||||
var it = require('./util/it');
|
||||
|
@ -16,7 +16,7 @@ describe('app', function() {
|
|||
});
|
||||
|
||||
it("Expose a `Model` to remote clients", function() {
|
||||
var Color = DataModel.extend('color', {name: String});
|
||||
var Color = PersistedModel.extend('color', {name: String});
|
||||
app.model(Color);
|
||||
Color.attachTo(db);
|
||||
|
||||
|
@ -24,14 +24,14 @@ describe('app', function() {
|
|||
});
|
||||
|
||||
it('uses singlar name as app.remoteObjects() key', function() {
|
||||
var Color = DataModel.extend('color', {name: String});
|
||||
var Color = PersistedModel.extend('color', {name: String});
|
||||
app.model(Color);
|
||||
Color.attachTo(db);
|
||||
expect(app.remoteObjects()).to.eql({ color: Color });
|
||||
});
|
||||
|
||||
it('uses singular name as shared class name', function() {
|
||||
var Color = DataModel.extend('color', {name: String});
|
||||
var Color = PersistedModel.extend('color', {name: String});
|
||||
app.model(Color);
|
||||
Color.attachTo(db);
|
||||
var classes = app.remotes().classes().map(function(c) {return c.name});
|
||||
|
@ -42,7 +42,7 @@ describe('app', function() {
|
|||
app.use(loopback.rest());
|
||||
request(app).get('/colors').expect(404, function(err, res) {
|
||||
if (err) return done(err);
|
||||
var Color = DataModel.extend('color', {name: String});
|
||||
var Color = PersistedModel.extend('color', {name: String});
|
||||
app.model(Color);
|
||||
Color.attachTo(db);
|
||||
request(app).get('/colors').expect(200, done);
|
||||
|
|
|
@ -6,7 +6,7 @@ describe('Change', function(){
|
|||
var memory = loopback.createDataSource({
|
||||
connector: loopback.Memory
|
||||
});
|
||||
TestModel = loopback.DataModel.extend('chtest', {}, {
|
||||
TestModel = loopback.PersistedModel.extend('chtest', {}, {
|
||||
trackChanges: true
|
||||
});
|
||||
this.modelName = TestModel.modelName;
|
||||
|
|
|
@ -36,9 +36,9 @@ describe('DataSource', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe.skip('DataModel Methods', function() {
|
||||
describe.skip('PersistedModel Methods', function() {
|
||||
it("List the enabled and disabled methods", function() {
|
||||
var TestModel = loopback.DataModel.extend('TestDataModel');
|
||||
var TestModel = loopback.PersistedModel.extend('TestPersistedModel');
|
||||
TestModel.attachTo(loopback.memory());
|
||||
|
||||
// assert the defaults
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var loopback = require('../../../');
|
||||
var DataModel = loopback.DataModel;
|
||||
var PersistedModel = loopback.PersistedModel;
|
||||
|
||||
exports.TestModel = DataModel.extend('TestModel', {}, {
|
||||
exports.TestModel = PersistedModel.extend('TestModel', {}, {
|
||||
trackChanges: true
|
||||
});
|
||||
|
|
|
@ -3,13 +3,13 @@ var loopback = require('../');
|
|||
describe('hidden properties', function () {
|
||||
beforeEach(function (done) {
|
||||
var app = this.app = loopback();
|
||||
var Product = this.Product = loopback.DataModel.extend('product',
|
||||
var Product = this.Product = loopback.PersistedModel.extend('product',
|
||||
{},
|
||||
{hidden: ['secret']}
|
||||
);
|
||||
Product.attachTo(loopback.memory());
|
||||
|
||||
var Category = this.Category = loopback.DataModel.extend('category');
|
||||
var Category = this.Category = loopback.PersistedModel.extend('category');
|
||||
Category.attachTo(loopback.memory());
|
||||
Category.hasMany(Product);
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ var loopback = require('../');
|
|||
var ACL = loopback.ACL;
|
||||
var Change = loopback.Change;
|
||||
var defineModelTestsWithDataSource = require('./util/model-tests');
|
||||
var DataModel = loopback.DataModel;
|
||||
var PersistedModel = loopback.PersistedModel;
|
||||
|
||||
var describe = require('./util/describe');
|
||||
|
||||
describe('Model / DataModel', function() {
|
||||
describe('Model / PersistedModel', function() {
|
||||
defineModelTestsWithDataSource({
|
||||
dataSource: {
|
||||
connector: loopback.Memory
|
||||
|
@ -16,7 +16,7 @@ describe('Model / DataModel', function() {
|
|||
|
||||
describe('Model.validatesUniquenessOf(property, options)', function() {
|
||||
it("Ensure the value for `property` is unique", function(done) {
|
||||
var User = DataModel.extend('user', {
|
||||
var User = PersistedModel.extend('user', {
|
||||
'first': String,
|
||||
'last': String,
|
||||
'age': Number,
|
||||
|
@ -71,7 +71,7 @@ describe.onServer('Remote Methods', function(){
|
|||
var app;
|
||||
|
||||
beforeEach(function () {
|
||||
User = DataModel.extend('user', {
|
||||
User = PersistedModel.extend('user', {
|
||||
'first': String,
|
||||
'last': String,
|
||||
'age': Number,
|
||||
|
@ -362,7 +362,7 @@ describe.onServer('Remote Methods', function(){
|
|||
|
||||
describe('Model.extend()', function(){
|
||||
it('Create a new model by extending an existing model', function() {
|
||||
var User = loopback.DataModel.extend('test-user', {
|
||||
var User = loopback.PersistedModel.extend('test-user', {
|
||||
email: String
|
||||
});
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ describe('RemoteConnector', function() {
|
|||
var test = this;
|
||||
remoteApp = this.remoteApp = loopback();
|
||||
remoteApp.use(loopback.rest());
|
||||
var ServerModel = this.ServerModel = loopback.DataModel.extend('TestModel');
|
||||
var ServerModel = this.ServerModel = loopback.PersistedModel.extend('TestModel');
|
||||
|
||||
remoteApp.model(ServerModel);
|
||||
|
||||
|
@ -48,7 +48,7 @@ describe('RemoteConnector', function() {
|
|||
|
||||
it('should support the save method', function (done) {
|
||||
var calledServerCreate = false;
|
||||
var RemoteModel = loopback.DataModel.extend('TestModel');
|
||||
var RemoteModel = loopback.PersistedModel.extend('TestModel');
|
||||
RemoteModel.attachTo(this.remote);
|
||||
|
||||
var ServerModel = this.ServerModel;
|
||||
|
|
|
@ -3,7 +3,7 @@ var loopback = require('../');
|
|||
var ACL = loopback.ACL;
|
||||
var Change = loopback.Change;
|
||||
var defineModelTestsWithDataSource = require('./util/model-tests');
|
||||
var DataModel = loopback.DataModel;
|
||||
var PersistedModel = loopback.PersistedModel;
|
||||
|
||||
describe('Replication / Change APIs', function() {
|
||||
beforeEach(function() {
|
||||
|
@ -11,12 +11,12 @@ describe('Replication / Change APIs', function() {
|
|||
var dataSource = this.dataSource = loopback.createDataSource({
|
||||
connector: loopback.Memory
|
||||
});
|
||||
var SourceModel = this.SourceModel = DataModel.extend('SourceModel', {}, {
|
||||
var SourceModel = this.SourceModel = PersistedModel.extend('SourceModel', {}, {
|
||||
trackChanges: true
|
||||
});
|
||||
SourceModel.attachTo(dataSource);
|
||||
|
||||
var TargetModel = this.TargetModel = DataModel.extend('TargetModel', {}, {
|
||||
var TargetModel = this.TargetModel = PersistedModel.extend('TargetModel', {}, {
|
||||
trackChanges: true
|
||||
});
|
||||
TargetModel.attachTo(dataSource);
|
||||
|
|
|
@ -3,7 +3,7 @@ var describe = require('./describe');
|
|||
var loopback = require('../../');
|
||||
var ACL = loopback.ACL;
|
||||
var Change = loopback.Change;
|
||||
var DataModel = loopback.DataModel;
|
||||
var PersistedModel = loopback.PersistedModel;
|
||||
var RemoteObjects = require('strong-remoting');
|
||||
|
||||
module.exports = function defineModelTestsWithDataSource(options) {
|
||||
|
@ -22,11 +22,11 @@ describe('Model Tests', function() {
|
|||
// setup a model / datasource
|
||||
dataSource = this.dataSource || loopback.createDataSource(options.dataSource);
|
||||
|
||||
var extend = DataModel.extend;
|
||||
var extend = PersistedModel.extend;
|
||||
|
||||
// create model hook
|
||||
DataModel.extend = function() {
|
||||
var extendedModel = extend.apply(DataModel, arguments);
|
||||
PersistedModel.extend = function() {
|
||||
var extendedModel = extend.apply(PersistedModel, arguments);
|
||||
|
||||
if(options.onDefine) {
|
||||
options.onDefine.call(test, extendedModel);
|
||||
|
@ -35,7 +35,7 @@ describe('Model Tests', function() {
|
|||
return extendedModel;
|
||||
}
|
||||
|
||||
User = DataModel.extend('user', {
|
||||
User = PersistedModel.extend('user', {
|
||||
'first': String,
|
||||
'last': String,
|
||||
'age': Number,
|
||||
|
|
Loading…
Reference in New Issue