waterline-schema.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Module dependencies
  3. */
  4. var Schema = require('./waterline-schema/schema');
  5. var ForeignKeys = require('./waterline-schema/foreignKeys');
  6. var JoinTables = require('./waterline-schema/joinTables');
  7. var References = require('./waterline-schema/references');
  8. var Checks = require('./waterline-schema/checks');
  9. // ██╗ ██╗ █████╗ ████████╗███████╗██████╗ ██╗ ██╗███╗ ██╗███████╗
  10. // ██║ ██║██╔══██╗╚══██╔══╝██╔════╝██╔══██╗██║ ██║████╗ ██║██╔════╝
  11. // ██║ █╗ ██║███████║ ██║ █████╗ ██████╔╝██║ ██║██╔██╗ ██║█████╗
  12. // ██║███╗██║██╔══██║ ██║ ██╔══╝ ██╔══██╗██║ ██║██║╚██╗██║██╔══╝
  13. // ╚███╔███╔╝██║ ██║ ██║ ███████╗██║ ██║███████╗██║██║ ╚████║███████╗
  14. // ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝
  15. //
  16. // ███████╗ ██████╗██╗ ██╗███████╗███╗ ███╗ █████╗
  17. // ██╔════╝██╔════╝██║ ██║██╔════╝████╗ ████║██╔══██╗
  18. // ███████╗██║ ███████║█████╗ ██╔████╔██║███████║
  19. // ╚════██║██║ ██╔══██║██╔══╝ ██║╚██╔╝██║██╔══██║
  20. // ███████║╚██████╗██║ ██║███████╗██║ ╚═╝ ██║██║ ██║
  21. // ╚══════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
  22. //
  23. // Used to build a Waterline Schema object from a set of loaded collections.
  24. // It should normalize attribute definitions and expand out associations. This
  25. // module is used internally to Waterline and provides no benefits outside of
  26. // it. The expanded properties added to associations are not appropriate for use
  27. // directly inside of your Waterline models.
  28. module.exports = function WaterlineSchema(collections, modelDefaults) {
  29. var schema = {};
  30. // Transform Collections into a basic schema
  31. schema = Schema(collections);
  32. // Map out and expand foreign keys on the collection schema attributes
  33. ForeignKeys(schema);
  34. // Build and map any generated join tables on the collection schema
  35. JoinTables(schema, modelDefaults);
  36. // Add References for Has Many Keys
  37. References(schema);
  38. // Run any final sanity checks on the schema
  39. Checks(schema);
  40. return schema;
  41. };