Socket
Socket
Sign inDemoInstall

redux-orm

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-orm - npm Package Compare versions

Comparing version 0.1.18 to 0.1.19

19

lib/descriptors.js

@@ -54,3 +54,9 @@ 'use strict';

var thisId = this.getId();
return declaredFromModel.get(_defineProperty({}, declaredFieldName, thisId));
var found = undefined;
try {
found = declaredFromModel.get(_defineProperty({}, declaredFieldName, thisId));
} catch (e) {
return null;
}
return found;
},

@@ -125,2 +131,6 @@ set: function set() {

qs.clear = function clear() {
throughQs['delete']();
};
qs.remove = function remove() {

@@ -141,5 +151,8 @@ var idsToRemove = undefined;

var attrShouldMatchThisId = reverse ? toFieldName : fromFieldName;
var attrInIdsToRemove = reverse ? fromFieldName : toFieldName;
var entitiesToDelete = throughModel.filter(function (through) {
if (through[fromFieldName] === thisId) {
if (idsToRemove.includes(through[toFieldName])) {
if (through[attrShouldMatchThisId] === thisId) {
if (idsToRemove.includes(through[attrInIdsToRemove])) {
return true;

@@ -146,0 +159,0 @@ }

3

lib/fields.js

@@ -13,6 +13,7 @@ "use strict";

var Field = function Field(toModelName) {
var Field = function Field(toModelName, relatedName) {
_classCallCheck(this, Field);
this.toModelName = toModelName;
this.relatedName = relatedName;
};

@@ -19,0 +20,0 @@

@@ -50,2 +50,3 @@ 'use strict';

exports.ManyToMany = _fields.ManyToMany;
exports.OneToOne = _fields.OneToOne;
exports.fk = fk;

@@ -52,0 +53,0 @@ exports.many = many;

@@ -211,3 +211,23 @@ 'use strict';

});
this._onDelete();
}
}, {
key: '_onDelete',
value: function _onDelete() {
var virtualFields = this.getClass().virtualFields;
for (var key in virtualFields) {
// eslint-disable-line
var field = virtualFields[key];
if (field instanceof _fields.ManyToMany) {
// Delete any many-to-many rows the entity is included in.
this[key].clear();
} else if (field instanceof _fields.ForeignKey || field instanceof _fields.OneToOne) {
// Set null to any foreign keys or one to ones pointed to
// this instance.
if (this[key] !== null) {
this[key][field.relatedName] = null;
}
}
}
}
}], [{

@@ -449,2 +469,4 @@ key: 'toString',

this.isSetUp = undefined;
this.definedProperties = {};
this.virtualFields = {};
}

@@ -629,2 +651,3 @@ }, {

Model.definedProperties = {};
Model.virtualFields = {};
Model.querySetClass = _QuerySet2['default'];

@@ -631,0 +654,0 @@

@@ -312,2 +312,8 @@ 'use strict';

});
var originalFlag = this._plain;
this.models.forEach(function (model) {
return model._onDelete();
});
this._plain = originalFlag;
}

@@ -314,0 +320,0 @@ }, {

@@ -229,5 +229,7 @@ 'use strict';

// Backwards.
var backwardsFieldName = (0, _utils.reverseFieldName)(model.modelName);
var backwardsFieldName = fieldInstance.relatedName ? fieldInstance.relatedName : (0, _utils.reverseFieldName)(model.modelName);
Object.defineProperty(toModel.prototype, backwardsFieldName, (0, _descriptors.backwardManyToOneDescriptor)(fieldName, model));
toModel.definedProperties[backwardsFieldName] = true;
toModel.virtualFields[backwardsFieldName] = new _fields.ForeignKey(model.modelName, fieldName);
} else if (fieldInstance instanceof _fields.ManyToMany) {

@@ -240,7 +242,10 @@ // Forwards.

model.definedProperties[fieldName] = true;
model.virtualFields[fieldName] = new _fields.ManyToMany(toModel.modelName, fieldName);
// Backwards.
var backwardsFieldName = (0, _utils.reverseFieldName)(model.modelName);
var backwardsFieldName = fieldInstance.relatedName ? fieldInstance.relatedName : (0, _utils.reverseFieldName)(model.modelName);
Object.defineProperty(toModel.prototype, backwardsFieldName, (0, _descriptors.manyToManyDescriptor)(model, toModel, throughModel, true));
toModel.definedProperties[backwardsFieldName] = true;
toModel.virtualFields[backwardsFieldName] = new _fields.ManyToMany(model.modelName, fieldName);
} else if (fieldInstance instanceof _fields.OneToOne) {

@@ -252,5 +257,7 @@ // Forwards.

// Backwards.
var backwardsFieldName = model.modelName.toLowerCase();
var backwardsFieldName = fieldInstance.relatedName ? fieldInstance.relatedName : model.modelName.toLowerCase();
Object.defineProperty(toModel.prototype, backwardsFieldName, (0, _descriptors.backwardOneToOneDescriptor)(fieldName, model));
model.definedProperties[backwardsFieldName] = true;
model.virtualFields[backwardsFieldName] = new _fields.OneToOne(model.modelName, fieldName);
}

@@ -257,0 +264,0 @@ });

@@ -468,7 +468,8 @@ 'use strict';

Genre = session.Genre;
Book.withId(0)['delete']();
Book.withId(1).genres.add(1, g3);
var nextState = session.reduce();
(0, _chai.expect)(nextState.BookGenres.items).to.have.length(4);
(0, _chai.expect)(nextState.BookGenres.items).to.deep.equal([0, 1, 2, 3]);
(0, _chai.expect)(nextState.BookGenres.items).to.have.length(2);
(0, _chai.expect)(nextState.BookGenres.items).to.deep.equal([2, 3]);
});

@@ -647,3 +648,4 @@

(0, _chai.expect)(nextUser.last().profile).to.be.undefined;
nextUser.last()['delete']();
});
});
{
"name": "redux-orm",
"version": "0.1.18",
"version": "0.1.19",
"description": "Simple ORM to manage and query your state trees",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -43,3 +43,9 @@ import UPDATE from './constants';

const thisId = this.getId();
return declaredFromModel.get({[declaredFieldName]: thisId});
let found;
try {
found = declaredFromModel.get({[declaredFieldName]: thisId});
} catch (e) {
return null;
}
return found;
},

@@ -111,2 +117,6 @@ set() {

qs.clear = function clear() {
throughQs.delete();
};
qs.remove = function remove(...entities) {

@@ -120,5 +130,8 @@ let idsToRemove;

const attrShouldMatchThisId = reverse ? toFieldName : fromFieldName;
const attrInIdsToRemove = reverse ? fromFieldName : toFieldName;
const entitiesToDelete = throughModel.filter(through => {
if (through[fromFieldName] === thisId) {
if (idsToRemove.includes(through[toFieldName])) {
if (through[attrShouldMatchThisId] === thisId) {
if (idsToRemove.includes(through[attrInIdsToRemove])) {
return true;

@@ -125,0 +138,0 @@ }

const Field = class Field {
constructor(toModelName) {
constructor(toModelName, relatedName) {
this.toModelName = toModelName;
this.relatedName = relatedName;
}

@@ -11,2 +12,6 @@ };

export {ForeignKey, ManyToMany, OneToOne};
export {
ForeignKey,
ManyToMany,
OneToOne,
};

@@ -28,2 +28,3 @@ import QuerySet from './QuerySet';

ManyToMany,
OneToOne,
fk,

@@ -30,0 +31,0 @@ many,

@@ -7,3 +7,7 @@ import forOwn from 'lodash/object/forOwn';

import QuerySet from './QuerySet';
import {ManyToMany} from './fields';
import {
ManyToMany,
ForeignKey,
OneToOne,
} from './fields';
import {CREATE, UPDATE, DELETE, ORDER} from './constants';

@@ -290,2 +294,4 @@ import {match} from './utils';

this.isSetUp = undefined;
this.definedProperties = {};
this.virtualFields = {};
}

@@ -511,3 +517,21 @@

});
this._onDelete();
}
_onDelete() {
const virtualFields = this.getClass().virtualFields;
for (const key in virtualFields) { // eslint-disable-line
const field = virtualFields[key];
if (field instanceof ManyToMany) {
// Delete any many-to-many rows the entity is included in.
this[key].clear();
} else if (field instanceof ForeignKey || field instanceof OneToOne) {
// Set null to any foreign keys or one to ones pointed to
// this instance.
if (this[key] !== null ) {
this[key][field.relatedName] = null;
}
}
}
}
};

@@ -517,4 +541,5 @@

Model.definedProperties = {};
Model.virtualFields = {};
Model.querySetClass = QuerySet;
export default Model;

@@ -252,2 +252,6 @@ import reject from 'lodash/collection/reject';

});
const originalFlag = this._plain;
this.models.forEach(model => model._onDelete());
this._plain = originalFlag;
}

@@ -254,0 +258,0 @@ };

@@ -5,4 +5,8 @@ import forOwn from 'lodash/object/forOwn';

import Model from './Model';
import {ForeignKey, ManyToMany, OneToOne} from './fields';
import {
ForeignKey,
ManyToMany,
OneToOne,
} from './fields';
import {
forwardManyToOneDescriptor,

@@ -171,3 +175,6 @@ backwardManyToOneDescriptor,

// Backwards.
const backwardsFieldName = reverseFieldName(model.modelName);
const backwardsFieldName = fieldInstance.relatedName
? fieldInstance.relatedName
: reverseFieldName(model.modelName);
Object.defineProperty(

@@ -179,2 +186,3 @@ toModel.prototype,

toModel.definedProperties[backwardsFieldName] = true;
toModel.virtualFields[backwardsFieldName] = new ForeignKey(model.modelName, fieldName);
} else if (fieldInstance instanceof ManyToMany) {

@@ -191,5 +199,9 @@ // Forwards.

model.definedProperties[fieldName] = true;
model.virtualFields[fieldName] = new ManyToMany(toModel.modelName, fieldName);
// Backwards.
const backwardsFieldName = reverseFieldName(model.modelName);
const backwardsFieldName = fieldInstance.relatedName
? fieldInstance.relatedName
: reverseFieldName(model.modelName);
Object.defineProperty(

@@ -201,2 +213,3 @@ toModel.prototype,

toModel.definedProperties[backwardsFieldName] = true;
toModel.virtualFields[backwardsFieldName] = new ManyToMany(model.modelName, fieldName);
} else if (fieldInstance instanceof OneToOne) {

@@ -212,3 +225,6 @@ // Forwards.

// Backwards.
const backwardsFieldName = model.modelName.toLowerCase();
const backwardsFieldName = fieldInstance.relatedName
? fieldInstance.relatedName
: model.modelName.toLowerCase();
Object.defineProperty(

@@ -220,2 +236,3 @@ toModel.prototype,

model.definedProperties[backwardsFieldName] = true;
model.virtualFields[backwardsFieldName] = new OneToOne(model.modelName, fieldName);
}

@@ -222,0 +239,0 @@ });

@@ -315,7 +315,8 @@ import {expect} from 'chai';

Genre = session.Genre;
Book.withId(0).delete();
Book.withId(1).genres.add(1, g3);
const nextState = session.reduce();
expect(nextState.BookGenres.items).to.have.length(4);
expect(nextState.BookGenres.items).to.deep.equal([0, 1, 2, 3]);
expect(nextState.BookGenres.items).to.have.length(2);
expect(nextState.BookGenres.items).to.deep.equal([2, 3]);
});

@@ -462,3 +463,4 @@

expect(nextUser.last().profile).to.be.undefined;
nextUser.last().delete();
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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