Repository: typedorm/typedorm (ts)

Issue:
Entity subclass without Attributes causes error
Hi, thanks for the nice library. I'm having some trouble with Entity inheritance as per https://github.com/typedorm/typedorm/blob/main/docs/entity-inheritance.md.

My use case is to have an abstract base class that defines most of the attributes I need, then create subclasses that inherit those attributes, and in some cases add their own, but often only use the inherited ones, and simply change the Entity PK/SK mappings to differentiate them in DDB. But this doesn't work, for example:

```ts
abstract class BaseEntity {
    @Attribute()
    foo: string;
}

@Entity({
    name: "SubEntity"
    primaryKey: {
        partitionKey: "whatever"
    },
})
class SubEntity extends BaseEntity {
   // no attributes
}
```
Causes this error:
```
Error: No entity with name "SubEntity" could be resolved,
      make sure they have been declared at the connection creation time.
```

Adding a single `@Attribute()` to `SubEntity` _does_ work, but I don't want to do that. The alternative is to declare some of the shared attributes in each subclass, which isn't very DRY. 

Can this be fixed, or is there another way to do this?

Pull request:
fix(core): allow `@Entity` declarations with no attributes
Fixes an issue where if trying to define an `@Entity` with no `@Attributes` it fails to build.


closes #138



Patch:
diff --git a/packages/common/src/metadata/metadata-storage.ts b/packages/common/src/metadata/metadata-storage.ts
index 8634d5c..6960e5f 100644
--- a/packages/common/src/metadata/metadata-storage.ts
+++ b/packages/common/src/metadata/metadata-storage.ts
@@ -79,8 +79,10 @@ export class MetadataStorage {
     const attributes = this._attributes.get(entityClass)?.values();
 
     if (!attributes) {
-      throw new Error(`No entity with name "${entityClass.name}" could be resolved, 
-      make sure they have been declared at the connection creation time.`);
+      // it is possible that entity might not have any attributes referenced such cases are
+      // when inherited entity contains all the attribute declarations and derived ones only defines schema for it
+      // Thus, instead of throwing an error, simply return [] list to continue processing other attributes
+      return [];
     }
     return Array.from(attributes);
   }


Test patch:
diff --git a/packages/core/src/classes/connection/__test__/entity-metadata-builder.spec.ts b/packages/core/src/classes/connection/__test__/entity-metadata-builder.spec.ts
index dd05b6b..1d558ca 100644
--- a/packages/core/src/classes/connection/__test__/entity-metadata-builder.spec.ts
+++ b/packages/core/src/classes/connection/__test__/entity-metadata-builder.spec.ts
@@ -229,6 +229,38 @@ test('builds metadata of derived entity with multiple levels of inheritance', ()
   ]);
 });
 
+/**
+ * Issue #138
+ */
+test('builds metadata of derived entity where derived entity does not have any explicit metadata defined', () => {
+  abstract class BaseEntity {
+    @Attribute()
+    id: string;
+  }
+
+  @Entity({
+    name: 'SubEntity',
+    primaryKey: {
+      partitionKey: 'SubEntity#{{id}}',
+      sortKey: 'SubEntity#{{id}}',
+    },
+  })
+  class SubEntity extends BaseEntity {
+    // no attributes
+  }
+
+  const [entityMetadata] = metadataBuilder.build([SubEntity]);
+
+  expect(entityMetadata.attributes).toEqual([
+    {
+      entityClass: SubEntity,
+      name: 'id',
+      table,
+      type: 'String',
+    },
+  ]);
+});
+
 test('builds entity metadata with global table config', () => {
   const globalTable = new Table({
     name: 'GlobalTable',