create.js 846 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict'
  2. var normalize = require('../../normalize')
  3. var Schema = require('./schema')
  4. var DefinedInfo = require('./defined-info')
  5. module.exports = create
  6. function create(definition) {
  7. var space = definition.space
  8. var mustUseProperty = definition.mustUseProperty || []
  9. var attributes = definition.attributes || {}
  10. var props = definition.properties
  11. var transform = definition.transform
  12. var property = {}
  13. var normal = {}
  14. var prop
  15. var info
  16. for (prop in props) {
  17. info = new DefinedInfo(
  18. prop,
  19. transform(attributes, prop),
  20. props[prop],
  21. space
  22. )
  23. if (mustUseProperty.indexOf(prop) !== -1) {
  24. info.mustUseProperty = true
  25. }
  26. property[prop] = info
  27. normal[normalize(prop)] = prop
  28. normal[normalize(info.attribute)] = prop
  29. }
  30. return new Schema(property, normal, space)
  31. }