lai:astronomy-simple-schema

v0.0.2Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Astronomy To Simple Schema

Convert Astronomy classes to Simple Schemas. Useful as a refactor path and for getting them to work in Autoforms.

Work in progress. Feel free to try at your own risk.

Installation

meteor add lai:astronomy-simple-schema

Usage

1Posts = new Mongo.Collection('posts');
2
3Post = Astro.Class({
4  name: 'Post',
5  collection: Posts,
6  fields: {
7    title: 'string',
8    publishedAt: 'date'
9  }
10});
11
12// Here's your Simple Schema!
13PostsSimpleSchema = Post.getSimpleSchema();
14

Limitations

Unfortunately, due to the superior awesomeness of Astronomy, a one-to-one mapping of Astronomy to Simple Schema is not really feasible at the moment nor practical when there are nested complex field types and arrays of validators. Therefore, you can pass a plain object into .getSimpleSchema to define certain Simple Schema fields that might be too complicated to translate:

1Post = Astro.Class({ ... });
2
3PostsSimpleSchema = Post.getSimpleSchema({
4  revisions: [new SimpleSchema({
5    date: {
6      type: Date
7    },
8    notes: {
9      type: String,
10      optional: true
11    }
12  })]
13});

Future Work

  • Account for nested complex fields
  • equal and equalTo validators (Could use autoValue but what happens when referencing values of other fields?)
  • Validator function parameters (what happens when referencing the value of another field?)
  • Arrays of validators? (is this even possible given the Ands and Ors)
  • Tests

Contributing

Any kind of insight, PRs, issues are welcome!