From dcaac48efd380a05b01454faf86f9043dc127f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Marty=C5=84ski?= Date: Sat, 16 Feb 2019 02:00:58 +0100 Subject: [PATCH] feat: remove object-hash from this package because it's out of this package scope --- package.json | 2 - ...ufLiteClassChecksum.ts => getFieldInfo.ts} | 7 - src/index.ts | 2 +- ...sChecksum.test.ts => getFieldInfo.test.ts} | 168 +----------------- yarn.lock | 9 - 5 files changed, 2 insertions(+), 186 deletions(-) rename src/{calculateProtobufLiteClassChecksum.ts => getFieldInfo.ts} (70%) rename test/{calculateProtobufLiteClassChecksum.test.ts => getFieldInfo.test.ts} (59%) diff --git a/package.json b/package.json index 24b2846..ee4df10 100644 --- a/package.json +++ b/package.json @@ -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", @@ -118,7 +117,6 @@ "typescript": "^3.0.3" }, "dependencies": { - "object-hash": "^1.3.1", "protobufjs": "^6.8.8" }, "husky": { diff --git a/src/calculateProtobufLiteClassChecksum.ts b/src/getFieldInfo.ts similarity index 70% rename from src/calculateProtobufLiteClassChecksum.ts rename to src/getFieldInfo.ts index c726c13..a6c03a6 100644 --- a/src/calculateProtobufLiteClassChecksum.ts +++ b/src/getFieldInfo.ts @@ -1,4 +1,3 @@ -import * as objectHash from "object-hash"; import { getMetadataObject, hasMetadataObject } from "./metadataHelpers"; import { IFieldInfo } from "./ProtobufLiteMetadata"; import { Constructable } from "./utils"; @@ -14,9 +13,3 @@ export const getFieldInfo = (Class: Constructable): IFieldInfo[] => { return metadataObject.collectFieldsInfo(); }; - -export const calculateProtobufLiteClassChecksum = (Class: Constructable): string => { - const fieldsInfo = getFieldInfo(Class); - - return objectHash(fieldsInfo); -}; diff --git a/src/index.ts b/src/index.ts index de248a5..7bc1cf5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -export * from "./calculateProtobufLiteClassChecksum"; +export * from "./getFieldInfo"; export * from "./encoderDecoderFunctions"; export * from "./ProtobufLiteProperty"; diff --git a/test/calculateProtobufLiteClassChecksum.test.ts b/test/getFieldInfo.test.ts similarity index 59% rename from test/calculateProtobufLiteClassChecksum.test.ts rename to test/getFieldInfo.test.ts index 0684000..14e5322 100644 --- a/test/calculateProtobufLiteClassChecksum.test.ts +++ b/test/getFieldInfo.test.ts @@ -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", () => { @@ -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) - ); - }); -}); diff --git a/yarn.lock b/yarn.lock index e4b4a52..f39337c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"