Skip to content

Instantly share code, notes, and snippets.

@vkarpov15
Created January 20, 2018 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkarpov15/9b10c975a535d0bbfb9d83285958839e to your computer and use it in GitHub Desktop.
Save vkarpov15/9b10c975a535d0bbfb9d83285958839e to your computer and use it in GitHub Desktop.
Modeling Stores and Products with Archetype
const Archetype = require('archetype');
// Generic product type, because prices are specific to each store
const ProductType = new Archetype({
name: {
$type: 'string',
$required: true
}
}).compile('ProductType');
// Extend the base `ProductType` to have a price
const StoreProductType = ProductType.
path('price', {
$type: 'number',
$required: true
}).
compile('StoreProductType');
// Each store now has an array of products that have prices
const StoreType = new Archetype({
products: {
$type: [StoreProductType],
$required: true,
$default: []
}
}).compile('StoreType');
// StoreType {
// products:
// [ StoreProductType { name: 'Professional AngularJS', price: 34.99 } ] }
console.log(new StoreType({
products: [
{ name: 'Professional AngularJS', price: 34.99 }
]
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment