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

bookshelf

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bookshelf - npm Package Compare versions

Comparing version 0.7.3 to 0.7.4

4

bookshelf.js

@@ -1,2 +0,2 @@

// Bookshelf.js 0.7.3
// Bookshelf.js 0.7.4
// ---------------

@@ -18,3 +18,3 @@

var bookshelf = {
VERSION: '0.7.3'
VERSION: '0.7.4'
};

@@ -21,0 +21,0 @@

{
"name": "bookshelf",
"version": "0.7.3",
"version": "0.7.4",
"description": "A lightweight ORM for PostgreSQL, MySQL, and SQLite3",

@@ -44,3 +44,3 @@ "main": "bookshelf.js",

"gulp-shell": "^0.2.5",
"knex": "0.6.10",
"knex": "0.6.16",
"mocha": "~1.20.1",

@@ -47,0 +47,0 @@ "mysql": "~2.3.2",

@@ -5,3 +5,3 @@ // Registry Plugin -

// -----
module.exports = function (Bookshelf) {
module.exports = function (bookshelf) {
'use strict';

@@ -15,7 +15,10 @@ var _ = require('lodash');

// Set up the methods for storing and retrieving models
// on the Bookshelf instance.
Bookshelf.model = function(name, ModelCtor) {
// on the bookshelf instance.
bookshelf.model = function(name, ModelCtor, staticProps) {
this._models = this._models || Object.create(null);
if (ModelCtor) {
preventOverwrite(this._models, name);
if (_.isPlainObject(ModelCtor)) {
ModelCtor = this.Model.extend(ModelCtor, staticProps);
}
this._models[name] = ModelCtor;

@@ -25,6 +28,9 @@ }

};
Bookshelf.collection = function(name, CollectionCtor) {
bookshelf.collection = function(name, CollectionCtor, staticProps) {
this._collections = this._collections || Object.create(null);
if (CollectionCtor) {
preventOverwrite(this._collections, name);
if (_.isPlainObject(CollectionCtor)) {
CollectionCtor = this.Model.extend(CollectionCtor, staticProps);
}
this._collections[name] = CollectionCtor;

@@ -41,3 +47,3 @@ }

if (typeof input === 'string') {
return Bookshelf.collection(input) || Bookshelf.model(input) || (function() {
return bookshelf.collection(input) || bookshelf.model(input) || (function() {
throw new Error('The model ' + input + ' could not be resolved from the registry plugin.');

@@ -49,6 +55,6 @@ })();

var Model = Bookshelf.Model;
var Collection = Bookshelf.Collection;
var Model = bookshelf.Model;
var Collection = bookshelf.Collection;
// Re-implement the `Bookshelf.Model` relation methods to include a check for the registered model.
// Re-implement the `bookshelf.Model` relation methods to include a check for the registered model.
_.each(['hasMany', 'hasOne', 'belongsToMany', 'morphOne', 'morphMany', 'belongsTo', 'through'], function(method) {

@@ -55,0 +61,0 @@ var original = Model.prototype[method];

@@ -34,7 +34,7 @@ var expect = require('chai').expect;

});
this.model = Bookshelf.model('Model', this.Model);
this.ModelObj = Bookshelf.model('Model', this.Model);
});
it('returns the registered model', function() {
expect(this.model).to.equal(this.Model);
expect(this.ModelObj).to.equal(this.Model);
});

@@ -46,2 +46,6 @@

it('assigns the tableName', function() {
expect(Bookshelf.model('Model').prototype.tableName).to.equal('records');
});
it('throws when there is a name conflict', function() {

@@ -53,2 +57,33 @@ expect(Bookshelf.model.bind(Bookshelf, 'Model', Bookshelf.Model)).to.throw();

describe('Registering Models with plain object', function() {
var noop = function() {};
beforeEach(function() {
Bookshelf._models = {};
this.Model = Bookshelf.model('Model', {
tableName: 'records'
}, {
noop: noop
});
});
it('assigns the model the name', function() {
expect(Bookshelf.model('Model')).to.equal(this.Model);
});
it('assigns the tableName', function() {
expect(Bookshelf.model('Model').prototype.tableName).to.equal('records');
});
it('assigns static props', function() {
expect(Bookshelf.model('Model').noop).to.equal(noop);
});
it('throws when there is a name conflict', function() {
expect(Bookshelf.model.bind(Bookshelf, 'Model', Bookshelf.Model)).to.throw();
});
});
describe('Registering Collections', function() {

@@ -55,0 +90,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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