@jamashita/anden-object
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -8,4 +8,3 @@ import { Cloneable } from '@jamashita/anden-type'; | ||
equals(other: unknown): boolean; | ||
hashCode(): number; | ||
} | ||
//# sourceMappingURL=Entity.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Entity = void 0; | ||
const anden_type_1 = require("@jamashita/anden-type"); | ||
const hash_it_1 = __importDefault(require("hash-it")); | ||
const Objet_1 = require("./Objet"); | ||
@@ -18,16 +14,13 @@ class Entity extends Objet_1.Objet { | ||
} | ||
if (this.hashCode() === other.hashCode()) { | ||
const identifier = this.getIdentifier(); | ||
if (identifier === other.getIdentifier()) { | ||
return true; | ||
} | ||
if ((0, anden_type_1.isEqualable)(identifier)) { | ||
return identifier.equals(other.getIdentifier()); | ||
} | ||
return false; | ||
} | ||
hashCode() { | ||
const h = this.hashor(this.getIdentifier()); | ||
if (anden_type_1.Kind.isNumber(h)) { | ||
return h; | ||
} | ||
return (0, hash_it_1.default)(Objet_1.Objet.identify(h)); | ||
} | ||
} | ||
exports.Entity = Entity; | ||
//# sourceMappingURL=Entity.js.map |
@@ -1,5 +0,7 @@ | ||
export * from './Mock/index'; | ||
export * from './mock/index'; | ||
export * from './Entity'; | ||
export * from './Objet'; | ||
export * from './RecursiveReferenceError'; | ||
export * from './Reference'; | ||
export * from './ValueObject'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -13,6 +17,8 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./Mock/index"), exports); | ||
__exportStar(require("./mock/index"), exports); | ||
__exportStar(require("./Entity"), exports); | ||
__exportStar(require("./Objet"), exports); | ||
__exportStar(require("./RecursiveReferenceError"), exports); | ||
__exportStar(require("./Reference"), exports); | ||
__exportStar(require("./ValueObject"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -8,5 +8,4 @@ import { Nominative } from '@jamashita/anden-type'; | ||
hashCode(): number; | ||
protected hashor<T>(value: T): T | number; | ||
toString(): string; | ||
} | ||
//# sourceMappingURL=Objet.d.ts.map |
@@ -25,8 +25,2 @@ "use strict"; | ||
} | ||
hashor(value) { | ||
if ((0, anden_type_1.isNominative)(value)) { | ||
return value.hashCode(); | ||
} | ||
return value; | ||
} | ||
toString() { | ||
@@ -33,0 +27,0 @@ return this.serialize(); |
@@ -8,4 +8,3 @@ import { Cloneable } from '@jamashita/anden-type'; | ||
equals(other: unknown): boolean; | ||
hashCode(): number; | ||
} | ||
//# sourceMappingURL=Entity.d.ts.map |
@@ -1,3 +0,2 @@ | ||
import { Kind } from '@jamashita/anden-type'; | ||
import hash from 'hash-it'; | ||
import { isEqualable } from '@jamashita/anden-type'; | ||
import { Objet } from './Objet'; | ||
@@ -12,15 +11,12 @@ export class Entity extends Objet { | ||
} | ||
if (this.hashCode() === other.hashCode()) { | ||
const identifier = this.getIdentifier(); | ||
if (identifier === other.getIdentifier()) { | ||
return true; | ||
} | ||
if (isEqualable(identifier)) { | ||
return identifier.equals(other.getIdentifier()); | ||
} | ||
return false; | ||
} | ||
hashCode() { | ||
const h = this.hashor(this.getIdentifier()); | ||
if (Kind.isNumber(h)) { | ||
return h; | ||
} | ||
return hash(Objet.identify(h)); | ||
} | ||
} | ||
//# sourceMappingURL=Entity.js.map |
@@ -1,5 +0,7 @@ | ||
export * from './Mock/index'; | ||
export * from './mock/index'; | ||
export * from './Entity'; | ||
export * from './Objet'; | ||
export * from './RecursiveReferenceError'; | ||
export * from './Reference'; | ||
export * from './ValueObject'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,5 +0,7 @@ | ||
export * from './Mock/index'; | ||
export * from './mock/index'; | ||
export * from './Entity'; | ||
export * from './Objet'; | ||
export * from './RecursiveReferenceError'; | ||
export * from './Reference'; | ||
export * from './ValueObject'; | ||
//# sourceMappingURL=index.js.map |
@@ -8,5 +8,4 @@ import { Nominative } from '@jamashita/anden-type'; | ||
hashCode(): number; | ||
protected hashor<T>(value: T): T | number; | ||
toString(): string; | ||
} | ||
//# sourceMappingURL=Objet.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { isNominative, Kind } from '@jamashita/anden-type'; | ||
import { Kind } from '@jamashita/anden-type'; | ||
import hash from 'hash-it'; | ||
@@ -19,8 +19,2 @@ export class Objet { | ||
} | ||
hashor(value) { | ||
if (isNominative(value)) { | ||
return value.hashCode(); | ||
} | ||
return value; | ||
} | ||
toString() { | ||
@@ -27,0 +21,0 @@ return this.serialize(); |
{ | ||
"name": "@jamashita/anden-object", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"private": false, | ||
@@ -25,8 +25,7 @@ "repository": { | ||
"clean:coverage": "rimraf coverage", | ||
"clean:dist": "rimraf dist", | ||
"clean:others": "rimraf *.log && rimraf tsconfig.build.tsbuildinfo" | ||
"clean:dist": "rimraf dist" | ||
}, | ||
"dependencies": { | ||
"@jamashita/anden-error": "^2.3.0", | ||
"@jamashita/anden-type": "^2.2.0", | ||
"@jamashita/anden-type": "^2.3.0", | ||
"hash-it": "5.0.2" | ||
@@ -33,0 +32,0 @@ }, |
@@ -1,3 +0,3 @@ | ||
import { MockEntity } from '../Mock/MockEntity'; | ||
import { MockValueObject } from '../Mock/MockValueObject'; | ||
import { MockEntity } from '../mock/MockEntity'; | ||
import { MockValueObject } from '../mock/MockValueObject'; | ||
@@ -7,5 +7,5 @@ describe('Entity', () => { | ||
it('returns true when the same instance given', () => { | ||
const vo: MockValueObject<boolean> = new MockValueObject<boolean>(true); | ||
const vo: MockValueObject<boolean> = new MockValueObject(true); | ||
const entity: MockEntity<MockValueObject<boolean>> = new MockEntity<MockValueObject<boolean>>(vo, {}); | ||
const entity: MockEntity<MockValueObject<boolean>> = new MockEntity(vo, {}); | ||
@@ -16,5 +16,5 @@ expect(entity.equals(entity)).toBe(true); | ||
it('returns false when the different class instance given', () => { | ||
const vo: MockValueObject<boolean> = new MockValueObject<boolean>(true); | ||
const vo: MockValueObject<boolean> = new MockValueObject(true); | ||
const entity: MockEntity<MockValueObject<boolean>> = new MockEntity<MockValueObject<boolean>>(vo, {}); | ||
const entity: MockEntity<MockValueObject<boolean>> = new MockEntity(vo, {}); | ||
@@ -25,9 +25,9 @@ expect(entity.equals(new MockValueObject('mock'))).toBe(false); | ||
it('returns true when the ids equal', () => { | ||
const vo1: MockValueObject<boolean> = new MockValueObject<boolean>(true); | ||
const vo2: MockValueObject<boolean> = new MockValueObject<boolean>(false); | ||
const vo3: MockValueObject<boolean> = new MockValueObject<boolean>(true); | ||
const vo1: MockValueObject<boolean> = new MockValueObject(true); | ||
const vo2: MockValueObject<boolean> = new MockValueObject(false); | ||
const vo3: MockValueObject<boolean> = new MockValueObject(true); | ||
const entity1: MockEntity<MockValueObject<boolean>> = new MockEntity<MockValueObject<boolean>>(vo1, {}); | ||
const entity2: MockEntity<MockValueObject<boolean>> = new MockEntity<MockValueObject<boolean>>(vo2, {}); | ||
const entity3: MockEntity<MockValueObject<boolean>> = new MockEntity<MockValueObject<boolean>>(vo3, {}); | ||
const entity1: MockEntity<MockValueObject<boolean>> = new MockEntity(vo1, {}); | ||
const entity2: MockEntity<MockValueObject<boolean>> = new MockEntity(vo2, {}); | ||
const entity3: MockEntity<MockValueObject<boolean>> = new MockEntity(vo3, {}); | ||
@@ -38,36 +38,2 @@ expect(entity1.equals(entity2)).toBe(false); | ||
}); | ||
describe('hashCode', () => { | ||
it('returns same value of the hashCode of id', () => { | ||
const vo: MockValueObject<undefined> = new MockValueObject<undefined>(undefined); | ||
const entity: MockEntity<MockValueObject<undefined>> = new MockEntity<MockValueObject<undefined>>(vo, {}); | ||
expect(vo.hashCode()).toBe(entity.hashCode()); | ||
}); | ||
it('only depends on the id value, even if the other values are changed, returns same hashCode', () => { | ||
const vo: MockValueObject<null> = new MockValueObject<null>(null); | ||
const entity: MockEntity<MockValueObject<null>> = new MockEntity<MockValueObject<null>>(vo, {}); | ||
const code1: number = entity.hashCode(); | ||
entity.setObject({ code1 }); | ||
const code2: number = entity.hashCode(); | ||
entity.setObject({ | ||
code1, | ||
code2 | ||
}); | ||
const code3: number = entity.hashCode(); | ||
entity.setObject({ | ||
code1, | ||
code2 | ||
}); | ||
expect(code1).toBe(code2); | ||
expect(code2).toBe(code3); | ||
}); | ||
}); | ||
}); |
@@ -27,3 +27,3 @@ import { asyncRandom, sequence } from '@jamashita/anden-helper'; | ||
it('describes string', () => { | ||
const dones: Array<Promise<void>> = sequence(100).map<Promise<void>>(async () => { | ||
const dones: Array<Promise<void>> = sequence(100).map(async (): Promise<void> => { | ||
const str: string = await asyncRandom(40); | ||
@@ -38,3 +38,3 @@ | ||
it('describes symbol', () => { | ||
const dones: Array<Promise<void>> = sequence(100).map<Promise<void>>(async () => { | ||
const dones: Array<Promise<void>> = sequence(100).map(async (): Promise<void> => { | ||
const sym: symbol = Symbol(await asyncRandom(40)); | ||
@@ -59,3 +59,3 @@ | ||
const dones: Array<Promise<void>> = sequence(100).map<Promise<void>>(async (i: number) => { | ||
const dones: Array<Promise<void>> = sequence(100).map(async (i: number): Promise<void> => { | ||
const [key, value]: Array<string> = await Promise.all<string>([ | ||
@@ -80,3 +80,3 @@ asyncRandom(i), | ||
const dones: Array<Promise<void>> = sequence(100).map<Promise<void>>(async (i: number) => { | ||
const dones: Array<Promise<void>> = sequence(100).map(async (i: number): Promise<void> => { | ||
const [key, value]: Array<string> = await Promise.all<string>([ | ||
@@ -97,3 +97,3 @@ asyncRandom(i), | ||
it('returns itself when it has toString()', () => { | ||
const dones: Array<Promise<void>> = sequence(100).map<Promise<void>>(async () => { | ||
const dones: Array<Promise<void>> = sequence(100).map(async (): Promise<void> => { | ||
const str: string = await asyncRandom(40); | ||
@@ -100,0 +100,0 @@ |
import { asyncRandom, sequence } from '@jamashita/anden-helper'; | ||
import { MockValueObject } from '../Mock/MockValueObject'; | ||
import { MockValueObject } from '../mock/MockValueObject'; | ||
@@ -9,3 +9,3 @@ describe('ValueObject', () => { | ||
const dones: Array<Promise<void>> = sequence(1_000).map<Promise<void>>(async (i: number) => { | ||
const dones: Array<Promise<void>> = sequence(1_000).map(async (i: number): Promise<void> => { | ||
const str: string = await asyncRandom(i); | ||
@@ -12,0 +12,0 @@ |
@@ -1,3 +0,2 @@ | ||
import { Cloneable, Kind } from '@jamashita/anden-type'; | ||
import hash from 'hash-it'; | ||
import { Cloneable, isEqualable } from '@jamashita/anden-type'; | ||
import { Objet } from './Objet'; | ||
@@ -19,18 +18,14 @@ | ||
} | ||
if (this.hashCode() === other.hashCode()) { | ||
const identifier: I = this.getIdentifier(); | ||
if (identifier === other.getIdentifier()) { | ||
return true; | ||
} | ||
if (isEqualable(identifier)) { | ||
return identifier.equals(other.getIdentifier()); | ||
} | ||
return false; | ||
} | ||
public override hashCode(): number { | ||
const h: I | number = this.hashor<I>(this.getIdentifier()); | ||
if (Kind.isNumber(h)) { | ||
return h; | ||
} | ||
return hash(Objet.identify(h)); | ||
} | ||
} |
@@ -1,4 +0,6 @@ | ||
export * from './Mock/index'; | ||
export * from './mock/index'; | ||
export * from './Entity'; | ||
export * from './Objet'; | ||
export * from './RecursiveReferenceError'; | ||
export * from './Reference'; | ||
export * from './ValueObject'; |
@@ -1,2 +0,2 @@ | ||
import { isNominative, Kind, Nominative } from '@jamashita/anden-type'; | ||
import { Kind, Nominative } from '@jamashita/anden-type'; | ||
import hash from 'hash-it'; | ||
@@ -29,10 +29,2 @@ | ||
protected hashor<T>(value: T): T | number { | ||
if (isNominative(value)) { | ||
return value.hashCode(); | ||
} | ||
return value; | ||
} | ||
public toString(): string { | ||
@@ -39,0 +31,0 @@ return this.serialize(); |
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
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
6
90979
835
Updated@jamashita/anden-type@^2.3.0