Permalink
Browse files

feat(orm): function for generating schema from entity

  • Loading branch information...
bas080
bas080 committed May 26, 2016
1 parent a8928da commit dd81d9b35dae07fd12989501a1f6e469260b80a2
Showing with 22 additions and 1 deletion.
  1. +3 −1 src/aurelia-form.js
  2. +19 −0 src/entity-schema.js
@@ -1,4 +1,5 @@
import {Config} from './config';
import {entitySchema} from './entity-schema';

function configure(aurelia, configCallback) {
let config = aurelia.container.get(Config);
@@ -13,5 +14,6 @@ function configure(aurelia, configCallback) {
}

export {
configure
configure,
entitySchema
};
@@ -0,0 +1,19 @@
/**
* Takes an entity and uses it's metadata to generate a form-schema.
*
* @param {object} entity
* @returns {object[]} the schema with the attributes.
*/
export function entitySchema(entity) {
const keys = Object.keys(entity);
let typeMap = entity.getMeta().metadata.types;

let schema = [];
for (let key of keys) {
schema.push({
key: key,
type: typeMap[key] || 'string' //defaults to string
});
}
return schema;
}

0 comments on commit dd81d9b

Please sign in to comment.