Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promised-models

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promised-models - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

lib/attribute.js

24

lib/list.js

@@ -7,6 +7,6 @@ /**

* @class
* @param {Model.Field} field
* @param {Model.Attribute} attribute
*/
var List = function (field) {
this._field = field;
var List = function (attribute) {
this._attribute = attribute;
};

@@ -19,3 +19,3 @@

List.prototype.isEqual = function (value) {
return this._field.isEqual(value);
return this._attribute.isEqual(value);
};

@@ -28,3 +28,3 @@

List.prototype.toArray = function () {
return this._field.value.slice();
return this._attribute.value.slice();
};

@@ -38,3 +38,3 @@

List.prototype.get = function (k) {
return this._field.value[k];
return this._attribute.value[k];
};

@@ -47,3 +47,3 @@

List.prototype.length = function () {
return this._field.value.length;
return this._attribute.value.length;
};

@@ -55,7 +55,7 @@

var res;
if (this._field.isListCashed(this._field.value)) {
this._field.value = this.toArray();
if (this._attribute.isListCashed(this._attribute.value)) {
this._attribute.value = this.toArray();
}
res = Array.prototype[methodName].apply(this._field.value, arguments);
this._field.emitListChange();
res = Array.prototype[methodName].apply(this._attribute.value, arguments);
this._attribute.emitListChange();
return res;

@@ -65,2 +65,2 @@ };

module.exports = List;
module.exports = List;

@@ -31,12 +31,12 @@ /**

this.storage = new Storage();
this.fields = Object.keys(this.fields || {}).reduce(function (fields, name) {
var Field = model.fields[name];
fields[name] = new (Field.inherit({
this.attributes = Object.keys(this.attributes || {}).reduce(function (attributes, name) {
var Attribute = model.attributes[name];
attributes[name] = new (Attribute.inherit({
name: name,
model: model
}))(data[name]);
return fields;
return attributes;
}, {});
this._fieldsAr = Object.keys(this.fields).map(function (name) {
return model.fields[name];
this._attributesAr = Object.keys(this.attributes).map(function (name) {
return model.attributes[name];
});

@@ -138,4 +138,4 @@ this.commit(this.CHANGE_BRANCH);

return model.ready().then(function () {
return Vow.all(model._fieldsAr.map(function (field) {
return field.validate();
return Vow.all(model._attributesAr.map(function (attribute) {
return attribute.validate();
}));

@@ -151,3 +151,3 @@ }).then(function (validateResults) {

if (!isValid) {
err.fields.push(model._fieldsAr[k]);
err.attributes.push(model._attributesAr[k]);
}

@@ -161,3 +161,3 @@ return err;

/**
* check if any field is changed
* check if any attribute is changed
* @prop {string} [branch=DEFAULT_BRANCH]

@@ -168,4 +168,4 @@ * @return {Boolean}

var model = this;
return Object.keys(this.fields).some(function (name) {
return model.fields[name].isChanged(branch);
return Object.keys(this.attributes).some(function (name) {
return model.attributes[name].isChanged(branch);
});

@@ -175,3 +175,3 @@ },

/**
* revert all fields to initial or last commited value
* revert all attributes to initial or last commited value
* @prop {string} [branch=DEFAULT_BRANCH]

@@ -181,4 +181,4 @@ */

var model = this;
return Object.keys(this.fields).forEach(function (name) {
return model.fields[name].revert(branch);
return Object.keys(this.attributes).forEach(function (name) {
return model.attributes[name].revert(branch);
});

@@ -193,4 +193,4 @@ },

var model = this;
return Object.keys(this.fields).forEach(function (name) {
return model.fields[name].commit(branch);
return Object.keys(this.attributes).forEach(function (name) {
return model.attributes[name].commit(branch);
});

@@ -200,6 +200,6 @@ },

/**
* set field value
* set attribute value
* @param {string|object} name or data
* @param {*} value
* @return {Boolean} if field found
* @return {Boolean} if attribute found
*/

@@ -214,4 +214,4 @@ set: function (name, value) {

});
} else if (this.fields[name]) {
this.fields[name].set(value);
} else if (this.attributes[name]) {
this.attributes[name].set(value);
} else {

@@ -225,9 +225,9 @@ return false;

/**
* get field valie
* @param {string} fieldName
* get attribute valie
* @param {string} attributeName
* @return {*}
*/
get: function (fieldName) {
this._throwMissedField(fieldName);
return this.fields[fieldName].get();
get: function (attributeName) {
this._throwMissedAttribute(attributeName);
return this.attributes[attributeName].get();
},

@@ -241,7 +241,7 @@

var model = this;
return Object.keys(this.fields).filter(function (name) {
return !model.fields[name].internal;
return Object.keys(this.attributes).filter(function (name) {
return !model.attributes[name].internal;
}).reduce(function (json, name) {
var field = model.fields[name];
json[name] = field.toJSON();
var attribute = model.attributes[name];
json[name] = attribute.toJSON();
return json;

@@ -252,4 +252,4 @@ }, {});

/**
* unbind events on fields or model
* @param {string} [field] space separated list
* unbind events on attributes or model
* @param {string} [attribute] space separated list
* @param {string} event space separated list

@@ -259,9 +259,9 @@ * @param {Function} cb

*/
un: function (field, event, cb, ctx) {
this._callEventEmitter('removeListener', field, event, cb, ctx);
un: function (attribute, event, cb, ctx) {
this._callEventEmitter('removeListener', attribute, event, cb, ctx);
},
/**
* bind events on fields or model
* @param {string} [field] space separated list
* bind events on attributes or model
* @param {string} [attribute] space separated list
* @param {string} event space separated list

@@ -271,4 +271,4 @@ * @param {Function} cb

*/
on: function (field, event, cb, ctx) {
this._callEventEmitter('on', field, event, cb, ctx);
on: function (attribute, event, cb, ctx) {
this._callEventEmitter('on', attribute, event, cb, ctx);
},

@@ -308,3 +308,3 @@

/**
* make all calculations for fields
* make all calculations for attributes
* @return {Promise}

@@ -326,11 +326,11 @@ */

model.commit(model.CALCULATIONS_BRANCH);
model._fieldsAr.forEach(function (field) {
if (field.calculate) {
calculations[field.name] = field.calculate();
model._attributesAr.forEach(function (attribute) {
if (attribute.calculate) {
calculations[attribute.name] = attribute.calculate();
}
if (field.amend && field.isChanged(model.CHANGE_BRANCH)) {
amendings.push(field.amend());
if (attribute.amend && attribute.isChanged(model.CHANGE_BRANCH)) {
amendings.push(attribute.amend());
}
if (field.ready) {
nestedCalculations.push(field.ready());
if (attribute.ready) {
nestedCalculations.push(attribute.ready());
}

@@ -356,8 +356,8 @@ });

if (model.isChanged(model.CHANGE_BRANCH)) {
changedFileds = model._fieldsAr.filter(function (field) {
return field.isChanged(model.CHANGE_BRANCH);
changedFileds = model._attributesAr.filter(function (attribute) {
return attribute.isChanged(model.CHANGE_BRANCH);
});
model.commit(model.CHANGE_BRANCH);
changedFileds.forEach(function (field) {
model._emitFieldChange(field);
changedFileds.forEach(function (attribute) {
model._emitAttributeChange(attribute);
});

@@ -369,5 +369,5 @@ model._emitChange();

/**
* bind events on fields or model
* bind events on attributes or model
* @param {string} method of EventEmitter
* @param {string} [field] space separated list
* @param {string} [attribute] space separated list
* @param {string} event space separated list

@@ -377,3 +377,3 @@ * @param {Function} cb

*/
_callEventEmitter: function (method, field, event, cb, ctx) {
_callEventEmitter: function (method, attribute, event, cb, ctx) {
var model = this;

@@ -383,10 +383,10 @@ if (typeof event !== 'string') {

cb = event;
event = field;
field = undefined;
event = attribute;
attribute = undefined;
}
ctx = ctx || this;
if (field) {
field.split(/\s+/).forEach(function (field) {
if (attribute) {
attribute.split(/\s+/).forEach(function (attribute) {
event.split(/\s+/).forEach(function (event) {
model._eventEmitter[method](event + ':' + field, cb, ctx);
model._eventEmitter[method](event + ':' + attribute, cb, ctx);
});

@@ -402,6 +402,6 @@ });

/**
* @param {Model.Field} field
* @param {Model.Attribute} attribute
*/
_emitFieldChange: function (field) {
this.trigger('change:' + field.name);
_emitAttributeChange: function (attribute) {
this.trigger('change:' + attribute.name);
},

@@ -413,5 +413,5 @@

_throwMissedField: function (fieldName) {
if (!this.fields[fieldName]) {
throw new Error('Unknown field ' + fieldName);
_throwMissedAttribute: function (attributeName) {
if (!this.attributes[attributeName]) {
throw new Error('Unknown attribute ' + attributeName);
}

@@ -428,20 +428,20 @@ }

fields: {
String: require('./fields/string'),
Number: require('./fields/number'),
Boolean: require('./fields/boolean'),
List: require('./fields/list'),
Model: require('./fields/model'),
ModelsList: require('./fields/models-list')
attributeTypes: {
String: require('./types/string'),
Number: require('./types/number'),
Boolean: require('./types/boolean'),
List: require('./types/list'),
Model: require('./types/model'),
ModelsList: require('./types/models-list')
},
/**
* @type {Field}
* @type {Attribute}
* @prop {*} [initValue]
*/
Field: require('./field'),
Attribute: require('./attribute'),
/**
* @class <{Error}>
* @prop {Array<{Field}>} fields
* @prop {Array<{Attribute}>} attributes
*/

@@ -451,3 +451,3 @@ ValidationError: (function () {

this.name = 'ValidationError';
this.fields = [];
this.attributes = [];
Error.call(this); //super constructor

@@ -454,0 +454,0 @@ Error.captureStackTrace(this, this.constructor);

{
"description": "promise based, typed attributes, nested models and collections",
"name": "promised-models",
"version": "0.0.3",
"version": "0.0.4",
"repository": "git@github.com:delfrrr/promised-models.git",
"keywords": [
"models",
"promise",
"nested",
"typed",
"backbone"
],
"licenses": [
{
"type": "MIT",
"url": "https://github.com/enb-make/enb/blob/master/LICENSE"
}
],
"engines": {

@@ -7,0 +20,0 @@ "node": ">= 0.10"

@@ -16,14 +16,17 @@ # Promised Models (in progress)

var Model = require('promises-models'),
FashionModel = new Model.inherit({
fields: {
name: Model.fields.String
}
}),
model = new FashionModel({
name: 'Kate'
});
console.log(model.get('name')); // 'Kate'
```js
var Model = require('promises-models'),
FashionModel = new Model.inherit({
attributes: {
name: Model.attributeTypes.String
}
}),
model = new FashionModel({
name: 'Kate'
});
model.get('name'); // 'Kate'
```
## Api reference (in progress)

@@ -35,9 +38,9 @@

Creates you own model class by extending `Model`. You can define fields, instance/class method and properties. Inheritance is build over [inherit](https://www.npmjs.com/package/inherit).
Creates you own model class by extending `Model`. You can define attributes, instance/class method and properties. Inheritance is build over [inherit](https://www.npmjs.com/package/inherit).
```
```js
var CountedModels = Model.inherit({
__constructor: function () {
this.__base.apply(this, arguments); //super
this.fields.index.set(this.__self._count); //static properties
this.attributes.index.set(this.__self._count); //static properties
this.__self._count ++;

@@ -56,5 +59,5 @@ },

#### fields `Model.fields`
#### attributeTypes `Model.attributeTypes`
Namespace for predefined types of fields. Supported types:
Namespace for predefined types of attributes. Supported types:

@@ -68,12 +71,12 @@ * `String`

You can extend default field types or create your own
You can extend default attribute types or create your own
```
var DateField = Model.fields.Number.inherit({
```js
var DateAttribute = Model.attributeTypes.Number.inherit({
//..
}),
FashionModel = Model.inherit({
fields: {
name: Model.fields.String,
birthDate: DateField
attributes: {
name: Model.attributeTypes.String,
birthDate: DateAttribute
}

@@ -83,17 +86,17 @@ });

**Note:** `models.fields` will be replaced in constructor with field instances.
**Note:** `models.attributes` will be replaced in constructor with attribute instances.
```
```js
var model = new FashionModel();
model.fields.birthDate instanceof DateField; //true
model.attributes.birthDate instanceof DateAttribute; //true
```
#### set `model.set(fieldName, value)`
#### set `model.set(attributeName, value)`
Set current value of field.
Set current value of attribute.
```
```js
var model = new FashionModel();
model.set('name', 'Kate');
model.fields.name.set('Kate');
model.attributes.name.set('Kate');
model.set({

@@ -105,7 +108,7 @@ name: 'Kate',

#### get `model.get(fieldName)`
#### get `model.get(attributeName)`
Get current value of field.
Get current value of attribute.
```
```js
var model = new FashionModel({

@@ -116,4 +119,4 @@ name: 'Kate',

model.get('name'); //Kate
model.fields.name.get(); //Kate
model.get('some'); //throws error as uknown field
model.attributes.name.get(); //Kate
model.get('some'); //throws error as uknown attribute
```

@@ -125,14 +128,14 @@

**Note:** You can create internal fields, wich wouldn't be included to returned object.
**Note:** You can create internal attributes, wich wouldn't be included to returned object.
```
```js
var FashionModel = new Model.inherit({
fields: {
name: Model.fields.String.inherit({
attributes: {
name: Model.attributeTypes.String.inherit({
internal: true;
}),
sename: Model.fields.String.inherit({
sename: Model.attributeTypes.String.inherit({
internal: true;
}),
fullName: Model.fields.String
fullName: Model.attributeTypes.String
}

@@ -153,7 +156,7 @@ }),

```
```js
var FashionModel = Model.inherit({
fields: {
name: Model.fields.String,
weight: Model.fields.Number.inherit({
attributes: {
name: Model.attributeTypes.String,
weight: Model.attributeTypes.Number.inherit({
default: 50

@@ -176,3 +179,3 @@ })

```
```js
var model = new FashionModel();

@@ -192,3 +195,3 @@ model.set({

```
```js
var model = new FashionModel({

@@ -206,3 +209,3 @@ name: 'Kate',

```
```js
var RENDERED = 'RENDERED';

@@ -223,8 +226,8 @@ model.on('change', function () {

* `change` – some of fields have been changed
* `change:fieldName` – `fieldName` have been changed
* `change` – some of attributes have been changed
* `change:attributeName` – `attributeName` have been changed
* `destruct` – model was destructed
* `calculate` – async calculations started
```
```js
model.on('change', this.changeHandler, this);

@@ -238,3 +241,3 @@ model.on('change:weight change:name', this.changeHandler, this);

```
```js
//sunscribe

@@ -255,8 +258,8 @@ model.on('change:weight change:name', this.changeHandler, this);

Validate model fields.
Validate model attributes.
```
```js
var FashionModel = Model.inherit({
fields: {
name: Model.fields.String.inherit({
attributes: {
name: Model.attributeTypes.String.inherit({
validate: function () {

@@ -278,3 +281,3 @@ return $.get('/validateName', {

if (err instanceof Model.ValidationError) {
console.log('Invalid fields:' + err.fields.join());
console.log('Invalid attributes:' + err.attributes.join());
} else {

@@ -290,7 +293,7 @@ return err;

```
```js
var FashionModel = Model.inherit({
fields: {
name: Model.fields.String,
ratingIndex: Model.fields.Number.inherit({
attributes: {
name: Model.attributeTypes.String,
ratingIndex: Model.attributeTypes.Number.inherit({
calculate: function () {

@@ -302,3 +305,3 @@ return $.get('/rating', {

}),
annualFee: Model.fields.Number
annualFee: Model.attributeTypes.Number
}

@@ -319,6 +322,6 @@ }),

```
```js
var FashionModel = Model.inherit({
fields: {
name: Model.fields.String
attributes: {
name: Model.attributeTypes.String
},

@@ -342,7 +345,7 @@ storage: Model.Storage.inherit({

```
```js
var FashionModel = Model.inherit({
fields: {
name: Model.fields.String,
weight: Model.fields.Number
attributes: {
name: Model.attributeTypes.String,
weight: Model.attributeTypes.Number
},

@@ -394,5 +397,5 @@ storage: Model.Storage.inherit({

```
```js
var FashionModel = Model.inherit({
fields: {
attributes: {
//..

@@ -406,8 +409,8 @@ },

#### Field `Model.Field`
#### Attribute `Model.Attribute`
Base class for model field
Base class for model attribute
```
var CustomField = Model.field.inherit({
```js
var CustomAttribute = Model.attribute.inherit({
//..

@@ -414,0 +417,0 @@ })

@@ -32,3 +32,3 @@

});
it('should trigger change:field with final calculation result', function (done) {
it('should trigger change:attribute with final calculation result', function (done) {
var model = new ModelClass();

@@ -78,10 +78,10 @@ model.on('change:asyncDepended', function () {

describe('Amend', function () {
it('should change other fields when amending field changes', function () {
it('should change other attributes when amending attribute changes', function () {
var model = new ModelClass();
return model.ready().then(function () {
model.set('amendingField', 'newValue');
expect(model.get('amendingField')).to.be.equal('newValue');
expect(model.get('amendedField')).to.be.equal('defaultValue');
model.set('amendingAttribute', 'newValue');
expect(model.get('amendingAttribute')).to.be.equal('newValue');
expect(model.get('amendedAttribute')).to.be.equal('defaultValue');
return model.ready().then(function () {
expect(model.get('amendedField')).to.be.equal('newValue');
expect(model.get('amendedAttribute')).to.be.equal('newValue');
});

@@ -94,7 +94,7 @@ });

model.on('change', function () {
expect(model.get('amendingField')).to.be.equal('newValue');
expect(model.get('amendedField')).to.be.equal('newValue');
expect(model.get('amendingAttribute')).to.be.equal('newValue');
expect(model.get('amendedAttribute')).to.be.equal('newValue');
done();
});
model.set('amendingField', 'newValue');
model.set('amendingAttribute', 'newValue');
}).done();

@@ -101,0 +101,0 @@ });

@@ -26,5 +26,5 @@ var expect = require('chai').expect;

});
it('should have fields', function () {
it('should have attributes', function () {
var model = new ModelClass();
expect(model).to.have.property('fields');
expect(model).to.have.property('attributes');
});

@@ -35,4 +35,4 @@ });

var model = new InheritedClass();
it('should have fields', function () {
expect(model).to.have.property('fields');
it('should have attributes', function () {
expect(model).to.have.property('attributes');
});

@@ -55,3 +55,3 @@ it('should have propA', function () {

});
it('should throw on unknown field', function () {
it('should throw on unknown attribute', function () {
expect(function () {

@@ -58,0 +58,0 @@ model.get('nonexist');

@@ -19,3 +19,3 @@

});
it('should bind on fields and events', function (done) {
it('should bind on attributes and events', function (done) {
var model = new ModelClass(),

@@ -63,3 +63,3 @@ count = 0;

});
describe('change:field', function () {
describe('change:attribute', function () {
var model, count;

@@ -70,3 +70,3 @@ beforeEach(function () {

});
it('should call change:field async', function (done) {
it('should call change:attribute async', function (done) {
model.on('change:a', function () {

@@ -73,0 +73,0 @@ count++;

var expect = require('chai').expect;
describe('List field', function () {
describe('List attribute', function () {
var Model = require('./models/with-list');

@@ -5,0 +5,0 @@ it('should set array', function () {

@@ -9,11 +9,11 @@ /**

module.exports = Model.inherit({
fields: {
a: Model.fields.String.inherit({
attributes: {
a: Model.attributeTypes.String.inherit({
default: 'a-0'
}),
b: Model.fields.String.inherit({
b: Model.attributeTypes.String.inherit({
calculate: function () {
var field = this;
var attribute = this;
return Vow.fulfill().delay(0).then(function () {
return 'b-' + field.model.get('a').split('-')[1];
return 'b-' + attribute.model.get('a').split('-')[1];
});

@@ -20,0 +20,0 @@ }

@@ -8,4 +8,4 @@ /**

module.exports = Models.inherit({
fields: {
a: Models.fields.String.inherit({
attributes: {
a: Models.attributeTypes.String.inherit({
type: 'string',

@@ -15,7 +15,7 @@ default: 'a'

b: Models.fields.String.inherit({
b: Models.attributeTypes.String.inherit({
type: 'string'
}),
c: Models.fields.String.inherit({
c: Models.attributeTypes.String.inherit({
type: 'string',

@@ -25,3 +25,3 @@ internal: true,

}),
withSyncValidation: Models.fields.String.inherit({
withSyncValidation: Models.attributeTypes.String.inherit({
type: 'string',

@@ -33,9 +33,9 @@ default: 'validValue',

}),
withAsyncValidation: Models.fields.String.inherit({
withAsyncValidation: Models.attributeTypes.String.inherit({
type: 'string',
default: 'validValue',
validate: function () {
var field = this;
var attribute = this;
return Vow.fulfill().delay(0).then(function () {
return field.value === 'validValue';
return attribute.value === 'validValue';
});

@@ -42,0 +42,0 @@ }

@@ -8,8 +8,8 @@ /**

module.exports = Models.inherit({
fields: {
a: Models.fields.String.inherit({
attributes: {
a: Models.attributeTypes.String.inherit({
default: 'a-0'
}),
b: Models.fields.String.inherit({
b: Models.attributeTypes.String.inherit({
calculate: function () {

@@ -20,3 +20,3 @@ return 'b-' + this.model.get('a').split('-')[1];

c: Models.fields.String.inherit({
c: Models.attributeTypes.String.inherit({
calculate: function () {

@@ -27,3 +27,3 @@ return 'c-' + this.model.get('b').split('-')[1];

async: Models.fields.String.inherit({
async: Models.attributeTypes.String.inherit({
calculate: function () {

@@ -36,7 +36,7 @@ return Vow.fulfill().delay(0).then(function () {

asyncDepended: Models.fields.String.inherit({
asyncDepended: Models.attributeTypes.String.inherit({
calculate: function () {
var field = this;
var attribute = this;
return Vow.fulfill().delay(0).then(function () {
var data = field.model.toJSON();
var data = attribute.model.toJSON();
return [data.a, data.b, data.c, data.async].join('-');

@@ -47,12 +47,12 @@ });

amendedField: Models.fields.String.inherit({
amendedAttribute: Models.attributeTypes.String.inherit({
default: 'defaultValue'
}),
amendingField: Models.fields.String.inherit({
amendingAttribute: Models.attributeTypes.String.inherit({
default: 'defaultValue',
amend: function () {
var field = this;
var attribute = this;
return Vow.fulfill().delay(0).then(function () {
field.model.set('amendedField', field.get());
attribute.model.set('amendedAttribute', attribute.get());
});

@@ -62,3 +62,3 @@ }

preprocessed: Models.fields.String.inherit({
preprocessed: Models.attributeTypes.String.inherit({
parse: function (value) {

@@ -65,0 +65,0 @@ if (typeof value !== 'string') {

@@ -8,5 +8,5 @@ /**

module.exports = Model.inherit({
fields: {
list: Model.fields.List
attributes: {
list: Model.attributeTypes.List
}
});

@@ -6,6 +6,6 @@ /**

NestedModel = Model.inherit({
fields: {
a: Model.fields.String,
b: Model.fields.String,
invalid: Model.fields.Number.inherit({
attributes: {
a: Model.attributeTypes.String,
b: Model.attributeTypes.String,
invalid: Model.attributeTypes.Number.inherit({
validate: function () {

@@ -19,10 +19,10 @@ return Boolean(this.value);

module.exports = Model.inherit({
fields: {
nested: Model.fields.Model.inherit({
attributes: {
nested: Model.attributeTypes.Model.inherit({
modelType: NestedModel
}),
nestedAsync: Model.fields.Model(require('./with-calculations')),
collection: Model.fields.ModelsList(require('./with-calculations')),
collectionWithInvalid: Model.fields.ModelsList(NestedModel)
nestedAsync: Model.attributeTypes.Model(require('./with-calculations')),
collection: Model.attributeTypes.ModelsList(require('./with-calculations')),
collectionWithInvalid: Model.attributeTypes.ModelsList(NestedModel)
}
});

@@ -8,7 +8,7 @@ /**

module.exports = Model.inherit({
fields: {
string: Model.fields.String,
number: Model.fields.Number,
boolean: Model.fields.Boolean
attributes: {
string: Model.attributeTypes.String,
number: Model.attributeTypes.Number,
boolean: Model.attributeTypes.Boolean
}
});

@@ -5,3 +5,3 @@ var expect = require('chai').expect;

var Model = require('./models/with-nested');
describe('model field', function () {
describe('model attribute', function () {
var data, model;

@@ -28,3 +28,3 @@ beforeEach(function () {

});
it('should trigger change:field on parent model', function (done) {
it('should trigger change:attribute on parent model', function (done) {
model.on('change:nested', function () {

@@ -31,0 +31,0 @@ done();

@@ -17,3 +17,3 @@

});
it('should insert and update calculated fields', function () {
it('should insert and update calculated attributes', function () {
var model1 = new Model();

@@ -20,0 +20,0 @@ model1.set('a', 'a-2');

var expect = require('chai').expect;
describe('Primitive field types', function () {
describe('Primitive attribute types', function () {
var Model = require('./models/with-types');

@@ -5,0 +5,0 @@ describe('string', function () {

@@ -16,3 +16,3 @@

});
it('should reject for invalid fields with async and sync validation', function () {
it('should reject for invalid attributes with async and sync validation', function () {
model.set('withSyncValidation', 'notValid');

@@ -38,3 +38,3 @@ return model.validate().always(function (p) {

});
it('should report invalid fields', function () {
it('should report invalid attributes', function () {
model.set({

@@ -50,5 +50,5 @@ withAsyncValidation: 'notValid',

expect(p.valueOf()).to.be.instanceOf(ModelClass.ValidationError);
expect(p.valueOf()).to.have.property('fields');
expect(p.valueOf()).to.have.deep.property('fields[0].name');
expect(p.valueOf()).to.have.deep.property('fields[1].name');
expect(p.valueOf()).to.have.property('attributes');
expect(p.valueOf()).to.have.deep.property('attributes[0].name');
expect(p.valueOf()).to.have.deep.property('attributes[1].name');
}

@@ -55,0 +55,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc