Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use decorators/metadata to create SimpleSchema #416

Closed
brettle opened this issue Jul 20, 2015 · 3 comments
Closed

Use decorators/metadata to create SimpleSchema #416

brettle opened this issue Jul 20, 2015 · 3 comments

Comments

@brettle
Copy link

brettle commented Jul 20, 2015

Typescript 1.5 adds support for decorators based on the ES7 decorators proposal, and it automatically adds type metadata to classes and properties. It would be nice if the resulting metadata could be used to create SimpleSchema objects. Ideally, I could write something like the following in Typescript:

class Person {
  @label('First and last name')
  fullName: string;

  @label('Date of birth')
  dob: Date;

  @label('Number of children')
  @min(0)
  numChildren: number;
}

schema = new SimpleSchema(Person);

And the resulting schema would be equivalent to:

schema = new SimpleSchema({
  fullName: {
    type: String,
    label: 'First and last name'
  },
  dob: {
    type: Date,
    label: 'Date of birth'
  },
  numChildren: {
    type: Number,
    label: "Number of children",
    min: 0
  }
});

Is anyone looking into this? Should it be implemented as a separate package, or would a pull request which added support be considered (assuming it doesn't introduce any new dependencies).

The implementation I'm imagining would detect the existence of the Reflect.metadata API and, if it exists, use it to find the metadata and build the schema.

Thoughts?

@ncubica
Copy link

ncubica commented Oct 17, 2015

have you done any kind of progress in this subject? I'm really interest in this kind of solution. Maybe we should start coding this.

@brettle
Copy link
Author

brettle commented Oct 18, 2015

I haven't done anything yet. If/when I do I'll post here. If you do (or anyone else does), please do the same.

@aldeed
Copy link
Collaborator

aldeed commented Nov 12, 2015

It should be a separate package, but if changes are needed in core to support plugging in the new package, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants