Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
feat: remove object-hash from this package because it's out of this p…
Browse files Browse the repository at this point in the history
…ackage scope
  • Loading branch information
elderapo committed Feb 16, 2019
1 parent ccda068 commit dcaac48
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 186 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
"@types/jest": "^24.0.3",
"@types/jest-diff": "^20.0.0",
"@types/node": "^11.9.4",
"@types/object-hash": "^1.2.0",
"benchmark": "^2.1.4",
"chalk": "^2.4.2",
"colors": "^1.3.2",
Expand Down Expand Up @@ -118,7 +117,6 @@
"typescript": "^3.0.3"
},
"dependencies": {
"object-hash": "^1.3.1",
"protobufjs": "^6.8.8"
},
"husky": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as objectHash from "object-hash";
import { getMetadataObject, hasMetadataObject } from "./metadataHelpers";
import { IFieldInfo } from "./ProtobufLiteMetadata";
import { Constructable } from "./utils";
Expand All @@ -14,9 +13,3 @@ export const getFieldInfo = (Class: Constructable<Object>): IFieldInfo[] => {

return metadataObject.collectFieldsInfo();
};

export const calculateProtobufLiteClassChecksum = (Class: Constructable<Object>): string => {
const fieldsInfo = getFieldInfo(Class);

return objectHash(fieldsInfo);
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./calculateProtobufLiteClassChecksum";
export * from "./getFieldInfo";
export * from "./encoderDecoderFunctions";
export * from "./ProtobufLiteProperty";
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "@abraham/reflection";

import { calculateProtobufLiteClassChecksum, ProtobufLiteProperty, getFieldInfo } from "../src";
import { getFieldInfo, ProtobufLiteProperty } from "../src";

describe("getFieldInfo", () => {
it("should throw if provided class with no metadata", () => {
Expand Down Expand Up @@ -274,168 +273,3 @@ describe("getFieldInfo", () => {
expect(() => getFieldInfo(Child)).toThrowError();
});
});

describe("calculateProtobufLiteClassChecksum", () => {
it("should throw if provided class with no metadata", () => {
class C1 {}

expect(() => calculateProtobufLiteClassChecksum(C1)).toThrowError();
});

it("should correctly calculate checksums for strings", () => {
class C1 {
@ProtobufLiteProperty()
name: string;
}

class C2 {
@ProtobufLiteProperty({ optional: true })
name?: string;
}

class C3 {
@ProtobufLiteProperty({ type: () => String })
names: string[];
}

expect(calculateProtobufLiteClassChecksum(C1)).toBe("32e9334202f312b74fff2d09be415564a44dfef1");

expect(calculateProtobufLiteClassChecksum(C2)).toBe("44fbe764c884bdcd4299031a6c95a3e18f7f94d9");

expect(calculateProtobufLiteClassChecksum(C2)).not.toBe(calculateProtobufLiteClassChecksum(C1));

expect(calculateProtobufLiteClassChecksum(C3)).toBe("921e745f25d63deb80936b9daf428cdd46ed4587");
});

it("should correctly calculate checksums for numbers", () => {
class C1 {
@ProtobufLiteProperty()
age: number;
}

class C2 {
@ProtobufLiteProperty({ optional: true })
age?: number;
}

class C3 {
@ProtobufLiteProperty({ type: () => Number })
ages: number[];
}

expect(calculateProtobufLiteClassChecksum(C1)).toBe("5571947d7ad3108fd28ddc5d5887efc147fb29ed");

expect(calculateProtobufLiteClassChecksum(C2)).toBe("82b88e10120379d3ff74642f97fdb1259e1f3105");

expect(calculateProtobufLiteClassChecksum(C2)).not.toBe(calculateProtobufLiteClassChecksum(C1));

expect(calculateProtobufLiteClassChecksum(C3)).toBe("c86042ccf8f1f14230c39a6b068edf1ea66ab55b");
});

it("should correctly calculate checksums for booleans", () => {
class C1 {
@ProtobufLiteProperty()
isTrue: boolean;
}

class C2 {
@ProtobufLiteProperty({ optional: true })
isTrue?: boolean;
}

class C3 {
@ProtobufLiteProperty({ type: () => Boolean })
isTrues: boolean[];
}

expect(calculateProtobufLiteClassChecksum(C1)).toBe("a2bdd3e45393664b445d6d1aad867da8924c4b99");

expect(calculateProtobufLiteClassChecksum(C2)).toBe("927b5fc6c9ec24e48e419c7aa457e44a5b41e073");

expect(calculateProtobufLiteClassChecksum(C2)).not.toBe(calculateProtobufLiteClassChecksum(C1));

expect(calculateProtobufLiteClassChecksum(C3)).toBe("13eb813067b5e4d33b53952296b008a4d8dc1010");
});

it("should correctly calculate checksums for Buffers", () => {
class C1 {
@ProtobufLiteProperty()
buffer: Buffer;
}

class C2 {
@ProtobufLiteProperty({ optional: true })
buffer?: Buffer;
}

class C3 {
@ProtobufLiteProperty({ type: () => Buffer })
buffers: Buffer[];
}

expect(calculateProtobufLiteClassChecksum(C1)).toBe("770d94168c43759c43f0c58dfcc77f79bbfca37d");

expect(calculateProtobufLiteClassChecksum(C2)).toBe("af573da26ae1d154ec49e9394e2acbec5deede50");

expect(calculateProtobufLiteClassChecksum(C2)).not.toBe(calculateProtobufLiteClassChecksum(C1));

expect(calculateProtobufLiteClassChecksum(C3)).toBe("b8e55fd8d90550054825391ce03701c5adc9e455");
});

it("should correctly calculate checksums for Dates", () => {
class C1 {
@ProtobufLiteProperty()
date: Date;
}

class C2 {
@ProtobufLiteProperty({ optional: true })
date?: Date;
}

class C3 {
@ProtobufLiteProperty({ type: () => Date })
dates: Date[];
}

expect(calculateProtobufLiteClassChecksum(C1)).toBe("1171038b07f309f5539d04618a4dc1f9d4e1f3f1");

expect(calculateProtobufLiteClassChecksum(C2)).toBe("3dd64c6895f3e1b65f957d100e4040d30a45a977");

expect(calculateProtobufLiteClassChecksum(C2)).not.toBe(calculateProtobufLiteClassChecksum(C1));

expect(calculateProtobufLiteClassChecksum(C3)).toBe("d9d1b2e83e64f6c3f9d1ebdcc5499d04a781b89e");
});

it("should correctly calculate checksums for inherited classes", () => {
class Parent {
@ProtobufLiteProperty()
parent: string;
}

class Child extends Parent {
@ProtobufLiteProperty()
child: string;
}

class ParentAndChild {
@ProtobufLiteProperty()
parent: string;

@ProtobufLiteProperty()
child: string;
}

expect(calculateProtobufLiteClassChecksum(Parent)).not.toBe(
calculateProtobufLiteClassChecksum(Child)
);

expect(calculateProtobufLiteClassChecksum(Parent)).not.toBe(
calculateProtobufLiteClassChecksum(ParentAndChild)
);

expect(calculateProtobufLiteClassChecksum(Child)).toBe(
calculateProtobufLiteClassChecksum(ParentAndChild)
);
});
});
9 changes: 0 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,6 @@
"@types/node@^11.9.4":
version "11.9.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.9.4.tgz#ceb0048a546db453f6248f2d1d95e937a6f00a14"
integrity sha512-Zl8dGvAcEmadgs1tmSPcvwzO1YRsz38bVJQvH1RvRqSR9/5n61Q1ktcDL0ht3FXWR+ZpVmXVwN1LuH4Ax23NsA==

"@types/object-hash@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@types/object-hash/-/object-hash-1.2.0.tgz#d65904331bd0b05c7d5ece75f9ddfdbe82affd30"

"@types/shelljs@^0.8.0":
version "0.8.2"
Expand Down Expand Up @@ -4659,10 +4654,6 @@ object-copy@^0.1.0:
define-property "^0.2.5"
kind-of "^3.0.3"

object-hash@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-1.3.1.tgz#fde452098a951cb145f039bb7d455449ddc126df"

object-keys@^1.0.12:
version "1.1.0"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.0.tgz#11bd22348dd2e096a045ab06f6c85bcc340fa032"
Expand Down

0 comments on commit dcaac48

Please sign in to comment.