Comparing version 2.4.1 to 2.4.2
@@ -58,2 +58,18 @@ "use strict"; | ||
/** | ||
* Check if provided values for {property} are different. Performs special checks for all Date types. | ||
* | ||
* @param {string} property | ||
* @param {Date} current | ||
* @param {Date} next | ||
* | ||
* @returns {boolean} | ||
*/ | ||
function areDifferent(property, current, next) { | ||
const isDate = ['date', 'dateTime', 'datetime', 'time'].indexOf(mapping.getType(property)) > -1; | ||
if (!isDate) { | ||
return current !== next; | ||
} | ||
return (new Date(current)).toString() !== (new Date(next)).toString(); | ||
} | ||
/** | ||
* Check if value is a setDirty value. | ||
@@ -167,3 +183,3 @@ * | ||
// We're proxying and the value changed. Register as dirty. | ||
if (isProxyActive() && target[property] !== value) { | ||
if (isProxyActive() && areDifferent(property, target[property], value)) { | ||
unitOfWork.registerDirty(target, property); | ||
@@ -170,0 +186,0 @@ } |
export declare class Simple { | ||
name: string; | ||
dateOfBirth: Date; | ||
static setMapping(mapping: any): void; | ||
} |
@@ -5,4 +5,5 @@ "use strict"; | ||
static setMapping(mapping) { | ||
mapping.field('dateOfBirth', { type: 'datetime' }); | ||
} | ||
} | ||
exports.Simple = Simple; |
import { Media } from './new/media'; | ||
declare var _default: typeof Media[]; | ||
declare const _default: (typeof Media)[]; | ||
export default _default; |
import { Media } from './old/media'; | ||
declare var _default: typeof Media[]; | ||
declare const _default: (typeof Media)[]; | ||
export default _default; |
@@ -78,2 +78,33 @@ "use strict"; | ||
}); | ||
it('should properly detect date changes', () => { | ||
const unitOfWork = getUnitOfWork(); | ||
const target = EntityProxy_1.EntityProxy.patchEntity(new Simple_1.Simple, unitOfWork.getEntityManager()); | ||
const dateConstant = new Date; | ||
const compare = new ArrayCollection_1.ArrayCollection; | ||
compare.add(target); | ||
target.name = 'date test'; | ||
target.dateOfBirth = dateConstant; | ||
unitOfWork.registerClean(target, true); | ||
target.activateProxying(); | ||
chai_1.assert.deepEqual(unitOfWork.getDirtyObjects(), new ArrayCollection_1.ArrayCollection); | ||
target.dateOfBirth = new Date; | ||
// Should remain clean | ||
chai_1.assert.deepEqual(unitOfWork.getDirtyObjects(), compare); | ||
}); | ||
it('should leave alone dates that are the same', () => { | ||
const unitOfWork = getUnitOfWork([Simple_1.Simple]); | ||
const target = EntityProxy_1.EntityProxy.patchEntity(new Simple_1.Simple, unitOfWork.getEntityManager()); | ||
const dateConstant = new Date; | ||
const dateClone = new Date(dateConstant); | ||
target.name = 'date test'; | ||
target.dateOfBirth = dateConstant; | ||
unitOfWork.registerClean(target, true); | ||
target.activateProxying(); | ||
chai_1.assert.strictEqual(dateClone.toString(), dateConstant.toString()); | ||
chai_1.assert.deepEqual(unitOfWork.getDirtyObjects(), new ArrayCollection_1.ArrayCollection); | ||
chai_1.assert.strictEqual((new Date(dateClone)).toString(), (new Date(dateConstant)).toString()); | ||
target.dateOfBirth = dateClone; | ||
// Should remain clean | ||
chai_1.assert.deepEqual(unitOfWork.getDirtyObjects(), new ArrayCollection_1.ArrayCollection); | ||
}); | ||
it('should register collection changes when adding an entity to a collection extended', () => { | ||
@@ -80,0 +111,0 @@ let unitOfWork = getUnitOfWork(); |
@@ -0,1 +1,11 @@ | ||
<a name="2.4.2"></a> | ||
## [2.4.2](https://github.com/SpoonX/wetland/compare/v2.4.1...v2.4.2) (2018-01-11) | ||
### Bug Fixes | ||
* **EntityProxy:** compare dates on their value to prevent false positives on dirty checks ([678729a](https://github.com/SpoonX/wetland/commit/678729a)) | ||
<a name="2.4.1"></a> | ||
@@ -2,0 +12,0 @@ ## [2.4.1](https://github.com/SpoonX/wetland/compare/v2.4.0...v2.4.1) (2017-11-20) |
{ | ||
"name": "wetland", | ||
"version": "2.4.1", | ||
"version": "2.4.2", | ||
"description": "A modern object-relational mapper (ORM) for node.js.", | ||
@@ -57,4 +57,4 @@ "main": "./dist/src/index.js", | ||
"sqlite3": "^3.1.4", | ||
"typescript": "^2.1.0-dev.20161008" | ||
"typescript": "^2.6.2" | ||
} | ||
} |
@@ -66,2 +66,21 @@ import {UnitOfWork} from './UnitOfWork'; | ||
/** | ||
* Check if provided values for {property} are different. Performs special checks for all Date types. | ||
* | ||
* @param {string} property | ||
* @param {Date} current | ||
* @param {Date} next | ||
* | ||
* @returns {boolean} | ||
*/ | ||
function areDifferent(property: string, current: Date, next: Date): Boolean { | ||
const isDate = ['date', 'dateTime', 'datetime', 'time'].indexOf(mapping.getType(property)) > -1; | ||
if (!isDate) { | ||
return current !== next; | ||
} | ||
return (new Date(current)).toString() !== (new Date(next)).toString(); | ||
} | ||
/** | ||
* Check if value is a setDirty value. | ||
@@ -210,3 +229,3 @@ * | ||
// We're proxying and the value changed. Register as dirty. | ||
if (isProxyActive() && target[property] !== value) { | ||
if (isProxyActive() && areDifferent(property, target[property], value)) { | ||
unitOfWork.registerDirty(target, property); | ||
@@ -213,0 +232,0 @@ } |
export class Simple { | ||
public name: string; | ||
public dateOfBirth: Date; | ||
public static setMapping(mapping) { | ||
mapping.field('dateOfBirth', {type: 'datetime'}) | ||
} | ||
} |
@@ -58,3 +58,3 @@ import {EntityProxy} from '../../src/EntityProxy'; | ||
assert.throws(() => { | ||
patched.single = simple; | ||
patched.single = simple as Simple; | ||
}, "Can't assign to 'Parent.single'. Expected instance of 'Simple'."); | ||
@@ -102,2 +102,47 @@ }); | ||
it('should properly detect date changes', () => { | ||
const unitOfWork = getUnitOfWork(); | ||
const target = EntityProxy.patchEntity(new Simple, unitOfWork.getEntityManager()); | ||
const dateConstant = new Date; | ||
const compare = new ArrayCollection; | ||
compare.add(target); | ||
target.name = 'date test'; | ||
target.dateOfBirth = dateConstant; | ||
unitOfWork.registerClean(target, true); | ||
target.activateProxying(); | ||
assert.deepEqual(unitOfWork.getDirtyObjects(), new ArrayCollection); | ||
target.dateOfBirth = new Date; | ||
// Should remain clean | ||
assert.deepEqual(unitOfWork.getDirtyObjects(), compare); | ||
}); | ||
it('should leave alone dates that are the same', () => { | ||
const unitOfWork = getUnitOfWork([Simple]); | ||
const target = EntityProxy.patchEntity(new Simple, unitOfWork.getEntityManager()); | ||
const dateConstant = new Date; | ||
const dateClone = new Date(dateConstant); | ||
target.name = 'date test'; | ||
target.dateOfBirth = dateConstant; | ||
unitOfWork.registerClean(target, true); | ||
target.activateProxying(); | ||
assert.strictEqual(dateClone.toString(), dateConstant.toString()); | ||
assert.deepEqual(unitOfWork.getDirtyObjects(), new ArrayCollection); | ||
assert.strictEqual((new Date(dateClone)).toString(), (new Date(dateConstant)).toString()); | ||
target.dateOfBirth = dateClone; | ||
// Should remain clean | ||
assert.deepEqual(unitOfWork.getDirtyObjects(), new ArrayCollection); | ||
}); | ||
it('should register collection changes when adding an entity to a collection extended', () => { | ||
@@ -104,0 +149,0 @@ let unitOfWork = getUnitOfWork(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
3090375
31069
1
366