Skip to content

Use reflection to do object mapping for a more declarative API. #25

@max-abclabs

Description

@max-abclabs

Currently using the schema in ts looks like this. This feels like 2x the code necessary since you are declaring the schema twice.
With reflection the API would be more declarative and make this code much smaller and easier to understand.

Without reflection:

interface Album {
  artist: string;
  title: string;
  year: number;
  genres: string[];
  outOfPublication: boolean;
}

class Album extends Entity {}

let schema = new Schema(Album, {
  artist: { type: 'string' },
  title: { type: 'string' },
  year: { type: 'number' },
  genres: { type: 'array' },
  outOfPublication: { type: 'boolean' }
})

With reflection:

@Entity()
class Album {
  @Property()
  artist: string;
  @Property()
  title: string;
  @Property()
  year: string;
  @Property()
  genres: string[];
  @Property()
  outOfPublication: boolean;
}

let schema = new Schema(Album);

This is just an example but demonstrates how declarative and powerful reflection can make this api.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions