0.1.4 • Published 8 years ago

babel-plugin-transform-orm v0.1.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

TransfORM

Write pretty model definitions for ORMs

Example

Original:

class Example extends Model {
    /** Example docstring */
    @required name : String = 'John'
}

Transformed:

var Example = Model.define({
    properties: [{
	    key: "name",
	    initializer: () => ["John"],
	    decorators: [required],
	    docstrings: ["Example docstring"],
	    type: String,
	    static: false
    }],
    setters: [],
    getters: [],
    methods: [],
    name: "Example",
    superClass: Model,
    docstrings: [],
    decorators: [],
    interfaces: []
})

Purpose

Allow introspection into a class by dumping an object containing all the class information (including decorators, Flow types, docstrings, class properties, methods and inheritance information). The static method define is called on the superclass (e.g. Model in the above example) so that users can control how the information is used.

Possible uses include GraphQL object definitions, and ORM/ODM models.

Usage

.babelrc

{
    "plugins": [
	["transform-orm", {
	    "globs": "**/*.model.js"
	}],
	"syntax-flow",
	"syntax-decorators",
	"syntax-class-properties"
    ]
}

All models with a superclass are transformed, so it is advised to limit the files transformed using the globs option in your .babelrc file. This can be either a single glob or an array of globs. If any of the patterns fail to match the filename then that file will be skipped.

License

MIT