New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

objection-unique

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objection-unique - npm Package Compare versions

Comparing version

to
1.2.0

# Changelog
## [v1.2.0](https://github.com/seegno/objection-unique/tree/v1.2.0) (2019-10-01)
[Full Changelog](https://github.com/seegno/objection-unique/compare/v1.1.0...v1.2.0)
**Merged pull requests:**
- Move options validation up [\#14](https://github.com/seegno/objection-unique/pull/14) ([vonagam](https://github.com/vonagam))
## [v1.1.0](https://github.com/seegno/objection-unique/tree/v1.1.0) (2019-10-01)

@@ -4,0 +11,0 @@ [Full Changelog](https://github.com/seegno/objection-unique/compare/v1.0.1...v1.1.0)

@@ -21,2 +21,6 @@ 'use strict';

if (isEmpty(options.fields) || isEmpty(options.identifiers)) {
throw new Error('Fields and identifiers options must be defined.');
}
return Model => {

@@ -32,6 +36,2 @@ return class extends Model {

if (isEmpty(options.fields) || isEmpty(options.identifiers)) {
throw new Error('Fields and identifiers options must be defined.');
}
return this.queryResolver(parent);

@@ -47,6 +47,2 @@ }

if (isEmpty(options.fields) || isEmpty(options.identifiers)) {
throw new Error('Fields and identifiers options must be defined.');
}
if (isEmpty(queryOptions.old)) {

@@ -53,0 +49,0 @@ throw new Error('Unique validation at update only works with queries started with $query.');

{
"name": "objection-unique",
"version": "1.1.0",
"version": "1.2.0",
"description": "objection-unique",

@@ -5,0 +5,0 @@ "keywords": [

@@ -18,15 +18,13 @@

describe('$beforeInsert', () => {
it('should throw an error if there is no fields or identifiers options.', async () => {
it('should throw an error if there is no fields or identifiers options.', () => {
try {
const TestModel = modelFactory();
try {
await TestModel.query().insert({});
fail();
} catch (e) {
expect(e.message).toBe('Fields and identifiers options must be defined.');
}
});
fail();
} catch (e) {
expect(e.message).toBe('Fields and identifiers options must be defined.');
}
});
describe('$beforeInsert', () => {
it('should throw a `ValidationError` with the unique fields that are already used.', async () => {

@@ -86,14 +84,2 @@ const TestModel = modelFactory({

describe('$beforeUpdate', () => {
it('should throw an error if there is no fields or identifiers options.', async () => {
const TestModel = modelFactory();
try {
await TestModel.query().update({});
fail();
} catch (e) {
expect(e.message).toBe('Fields and identifiers options must be defined.');
}
});
it('should throw an error if update is not a $query method.', async () => {

@@ -100,0 +86,0 @@ const TestModel = modelFactory({

@@ -6,2 +6,3 @@

import compoundModelFactory from './compound-model-factory';
import modelFactory from './model-factory';

@@ -14,4 +15,4 @@

export default async function() {
const TestModel = modelFactory();
const CompoundTestModel = modelFactory();
const TestModel = modelFactory({ fields: ['foo', 'bar'] });
const CompoundTestModel = compoundModelFactory({ fields: [['bar', 'foo']] });

@@ -18,0 +19,0 @@ await TestModel.query().truncate();