Repository: typedorm/typedorm (ts)

Issue:
Add Helper function to return entity metadata from given entity input
When Either entity name, entity with value or rawDynamoEntity is provided return entity metadata.

i.e when data is received in streams, this can be used to identity which entity record is present in streams

Pull request description:
feat(common): add helper to get entity definition
closes #58 

Patch:
diff --git a/packages/common/src/metadata/metadata-storage.ts b/packages/common/src/metadata/metadata-storage.ts
index 73a297f..5ddf0c8 100644
--- a/packages/common/src/metadata/metadata-storage.ts
+++ b/packages/common/src/metadata/metadata-storage.ts
@@ -58,6 +58,10 @@ export class MetadataStorage {
     this._attributes = new Map();
   }
 
+  getEntityByName(name: string) {
+    return this.entities.find(en => en.name === name);
+  }
+
   hasKnownEntity<Entity>(entityClass: EntityTarget<Entity>) {
     return this._entities.has(entityClass);
   }
diff --git a/packages/common/src/utils/get-entity-definition.ts b/packages/common/src/utils/get-entity-definition.ts
new file mode 100644
index 0000000..506d1ac
--- /dev/null
+++ b/packages/common/src/utils/get-entity-definition.ts
@@ -0,0 +1,17 @@
+import {MetadataManager} from '../metadata/metadata-manager';
+
+export function getEntityDefinition<Entity>(input: string | Entity) {
+  if (typeof input === 'string') {
+    return MetadataManager.metadataStorage.getEntityByName(input);
+  }
+
+  if (typeof input === 'object' && input !== null) {
+    const entityName = (input as any).__en;
+
+    if (!entityName) {
+      return;
+    }
+    return MetadataManager.metadataStorage.getEntityByName(entityName);
+  }
+  return;
+}


Test patch:
diff --git a/packages/common/src/utils/__test__/get-entity-definition.spec.ts b/packages/common/src/utils/__test__/get-entity-definition.spec.ts
new file mode 100644
index 0000000..7b2763d
--- /dev/null
+++ b/packages/common/src/utils/__test__/get-entity-definition.spec.ts
@@ -0,0 +1,46 @@
+import {Entity} from '@typedorm/common';
+import {Attribute} from '../../decorators/attribute.decorator';
+import {getEntityDefinition} from '../get-entity-definition';
+
+@Entity({
+  name: 'user',
+  primaryKey: {
+    partitionKey: '{{id}}',
+  },
+})
+class User {
+  @Attribute()
+  id: string;
+
+  @Attribute()
+  name: string;
+}
+
+test('returns entity definition by name', () => {
+  const definition = getEntityDefinition('user');
+
+  expect(definition).toEqual({
+    name: 'user',
+    primaryKey: {
+      partitionKey: '{{id}}',
+    },
+    target: User,
+  });
+});
+
+test('returns entity definition by entity data', () => {
+  // this is what is stored to dynamodb
+  const definition = getEntityDefinition({
+    id: '1',
+    name: 'test',
+    __en: 'user',
+  });
+
+  expect(definition).toEqual({
+    name: 'user',
+    primaryKey: {
+      partitionKey: '{{id}}',
+    },
+    target: User,
+  });
+});