Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

redux-orm

Package Overview
Dependencies
2
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

3

lib/Backend.js

@@ -59,3 +59,4 @@ 'use strict';

* @param {Number} id - the id of the object to get
* @return {Object} A reference to the raw object in the state.
* @return {Object|undefined} A reference to the raw object in the state or
* `undefined` if not found.
*/

@@ -62,0 +63,0 @@

@@ -6,5 +6,10 @@ "use strict";

});
var _bind = Function.prototype.bind;
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
exports.fk = fk;
exports.many = many;
exports.oneToOne = oneToOne;
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

@@ -32,2 +37,3 @@

})(Field);
exports.ForeignKey = ForeignKey;
var ManyToMany = (function (_Field2) {

@@ -44,2 +50,3 @@ _inherits(ManyToMany, _Field2);

})(Field);
exports.ManyToMany = ManyToMany;
var OneToOne = (function (_Field3) {

@@ -57,4 +64,26 @@ _inherits(OneToOne, _Field3);

exports.ForeignKey = ForeignKey;
exports.ManyToMany = ManyToMany;
exports.OneToOne = OneToOne;
exports.OneToOne = OneToOne;
function fk() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return new (_bind.apply(ForeignKey, [null].concat(args)))();
}
function many() {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return new (_bind.apply(ManyToMany, [null].concat(args)))();
}
function oneToOne() {
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return new (_bind.apply(OneToOne, [null].concat(args)))();
}

@@ -31,14 +31,2 @@ 'use strict';

function fk(relatedModelName) {
return new _fields.ForeignKey(relatedModelName);
}
function many(relatedModelName) {
return new _fields.ManyToMany(relatedModelName);
}
function oneToOne(relatedModelName) {
return new _fields.OneToOne(relatedModelName);
}
exports.QuerySet = _QuerySet2['default'];

@@ -52,5 +40,5 @@ exports.Backend = _Backend2['default'];

exports.OneToOne = _fields.OneToOne;
exports.fk = fk;
exports.many = many;
exports.oneToOne = oneToOne;
exports.fk = _fields.fk;
exports.many = _fields.many;
exports.oneToOne = _fields.oneToOne;
exports['default'] = _Model2['default'];

@@ -594,2 +594,9 @@ 'use strict';

}
/**
* Returns a Model instance for the object with id `id`.
* @param {*} id - the `id` of the object to get
* @throws If object with id `id` doesn't exist
* @return {Model} `Model` instance with id `id`
*/
}, {

@@ -599,3 +606,7 @@ key: 'withId',

var ModelClass = this;
return new ModelClass(this.accessId(id));
var ref = this.accessId(id);
if (typeof ref === 'undefined') {
throw new Error(this.modelName + ' instance with id ' + id + ' not found');
}
return new ModelClass(ref);
}

@@ -602,0 +613,0 @@

@@ -102,7 +102,16 @@ 'use strict';

it('many-to-many relationship descriptors work', function () {
it('withId throws if model instance not found', function () {
var _session3 = session;
var Book = _session3.Book;
var Genre = _session3.Genre;
(0, _chai.expect)(function () {
return Book.withId(10);
}).to['throw'](Error);
});
it('many-to-many relationship descriptors work', function () {
var _session4 = session;
var Book = _session4.Book;
var Genre = _session4.Genre;
// Forward (from many-to-many field declaration)

@@ -123,5 +132,5 @@ var book = Book.first();

it('foreign key relationship descriptors work', function () {
var _session4 = session;
var Book = _session4.Book;
var Author = _session4.Author;
var _session5 = session;
var Book = _session5.Book;
var Author = _session5.Author;

@@ -143,5 +152,5 @@ // Forward

it('one-to-one relationship descriptors work', function () {
var _session5 = session;
var Book = _session5.Book;
var Cover = _session5.Cover;
var _session6 = session;
var Book = _session6.Book;
var Cover = _session6.Cover;

@@ -148,0 +157,0 @@ // Forward

@@ -99,5 +99,5 @@ 'use strict';

return {
author: new _fields.ForeignKey('Author', 'books'),
cover: new _fields.OneToOne('Cover'),
genres: new _fields.ManyToMany('Genre', 'books')
author: (0, _fields.fk)('Author', 'books'),
cover: (0, _fields.oneToOne)('Cover'),
genres: (0, _fields.many)('Genre', 'books')
};

@@ -104,0 +104,0 @@ }

{
"name": "redux-orm",
"version": "0.2.0",
"version": "0.3.0",
"description": "Simple ORM to manage and query your state trees",

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

@@ -121,9 +121,10 @@ redux-orm

return session.Author.map(author => {
// Returns a shallow copy of the raw author object,
// Returns a reference to the raw object in the store,
// so it doesn't include any reverse or m2m fields.
const obj = author.toPlain();
const obj = author.ref;
// Object.keys(obj) === ['id', 'name']
return Object.assign(obj, {
books: author.books.plain.map(book => book.name),
return Object.assign({}, obj, {
books: author.books.withRefs.map(book => book.name),
});

@@ -407,2 +408,8 @@ });

### 0.3.0
**Breaking changes**:
- `Model.withId(id)` now throws if object with id `id` does not exist in the database.
### 0.2.0

@@ -419,2 +426,4 @@

- Removed `.toPlain()` method from `Model`, which returned a copy of the Model instance's property values. To replace that, `ref` instance getter was added. It returns a reference to the plain JavaScript object in the database. So you can do `Book.withId(0).ref`. If you need a copy, you can do `Object.assign({}, Book.withId(0).ref)`.
- Removed `.fromEmpty()` instance method from `Schema`.
- Removed `.setReducer()` instance method from `Schema`. You can just do `ModelClass.reducer = reducerFunc;`.

@@ -421,0 +430,0 @@

@@ -33,3 +33,4 @@ import find from 'lodash/collection/find';

* @param {Number} id - the id of the object to get
* @return {Object} A reference to the raw object in the state.
* @return {Object|undefined} A reference to the raw object in the state or
* `undefined` if not found.
*/

@@ -36,0 +37,0 @@ accessId(branch, id) {

@@ -8,10 +8,16 @@ const Field = class Field {

const ForeignKey = class ForeignKey extends Field {};
const ManyToMany = class ManyToMany extends Field {};
const OneToOne = class OneToOne extends Field {};
export const ForeignKey = class ForeignKey extends Field {};
export const ManyToMany = class ManyToMany extends Field {};
export const OneToOne = class OneToOne extends Field {};
export {
ForeignKey,
ManyToMany,
OneToOne,
};
export function fk(...args) {
return new ForeignKey(...args);
}
export function many(...args) {
return new ManyToMany(...args);
}
export function oneToOne(...args) {
return new OneToOne(...args);
}

@@ -6,16 +6,4 @@ import QuerySet from './QuerySet';

import Session from './Session';
import {ForeignKey, ManyToMany, OneToOne} from './fields';
import {ForeignKey, ManyToMany, OneToOne, fk, many, oneToOne} from './fields';
function fk(relatedModelName) {
return new ForeignKey(relatedModelName);
}
function many(relatedModelName) {
return new ManyToMany(relatedModelName);
}
function oneToOne(relatedModelName) {
return new OneToOne(relatedModelName);
}
export {

@@ -22,0 +10,0 @@ QuerySet,

@@ -373,5 +373,15 @@ import forOwn from 'lodash/object/forOwn';

/**
* Returns a Model instance for the object with id `id`.
* @param {*} id - the `id` of the object to get
* @throws If object with id `id` doesn't exist
* @return {Model} `Model` instance with id `id`
*/
static withId(id) {
const ModelClass = this;
return new ModelClass(this.accessId(id));
const ref = this.accessId(id);
if (typeof ref === 'undefined') {
throw new Error(`${this.modelName} instance with id ${id} not found`);
}
return new ModelClass(ref);
}

@@ -378,0 +388,0 @@

@@ -95,2 +95,7 @@ import {expect} from 'chai';

it('withId throws if model instance not found', () => {
const { Book } = session;
expect(() => Book.withId(10)).to.throw(Error);
});
it('many-to-many relationship descriptors work', () => {

@@ -97,0 +102,0 @@ const {

import Schema from '../Schema';
import Model from '../Model';
import {ForeignKey, ManyToMany, OneToOne} from '../fields';
import {fk, many, oneToOne} from '../fields';

@@ -80,5 +80,5 @@ /**

return {
author: new ForeignKey('Author', 'books'),
cover: new OneToOne('Cover'),
genres: new ManyToMany('Genre', 'books'),
author: fk('Author', 'books'),
cover: oneToOne('Cover'),
genres: many('Genre', 'books'),
};

@@ -85,0 +85,0 @@ }

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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc