Created
December 16, 2014 00:51
-
-
Save eddieajau/0b0d5d264eecced8a9fb to your computer and use it in GitHub Desktop.
Clean architecture for basic entity CRUD in Node.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Collection Interface. | |
* | |
* Concrete implementations would exist INSIDE the boundary interfaces. | |
* | |
* - Must be able to add one or more entities to the collection. | |
* - Must be able to find entities in the collection. | |
* - Must be able update entities in the collection. | |
* - Must be able to remove entities from the collection. | |
* | |
* - Might have a name? | |
* - Might be able to persist data? | |
* - Might validate an Entity against a schema? | |
* | |
* @param {string} [name] - The name of the collection? | |
* @param {Storage} [storage] - A persistant storage (default: MemoryStorage). | |
*/ | |
function Collection(name, storage) { | |
} | |
Collection.prototype.create = function (array) {}; | |
Collection.prototype.find = function (criteria, sorting) {}; | |
Collection.prototype.update = function (array) {}; | |
Collection.prototype.create = function (array) {}; | |
module.exports = Collection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Entity. | |
* | |
* - Should just hold the properties of an Entity. | |
* | |
* - Might know about its relationship to other entities? | |
*/ | |
function Entity(properties) { | |
} | |
module.exports = Entity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Storage Interface. | |
* | |
* Concrete implementations would exist OUTSIDE the boundary interface. | |
* | |
* - Must be able to create entities in the storage | |
* - Must be able to find entities in the storage | |
* - Must be able to update entities in the storage | |
* - Must be able to remove entities from the storage | |
* | |
* - Might need to transform or filter the data before it is stored (for example, encrypt it, compile a markup language)? | |
* - Might need to transform or filter the entity after it is read (for example, decrypt it, convert markup to HTML)? | |
* | |
* @param {object} [config] - Optional storage configuration data. | |
* @param {object} [plugins] - Optional hash of plugins, perhaps: { inputFilter: foo, outputFilter: bar }. | |
*/ | |
function Storage(config, plugins) { | |
} | |
Storage.prototype.create = function (array) {}; | |
Storage.prototype.find = function (criteria, sorting) {}; | |
Storage.prototype.update = function (array) {}; | |
Storage.prototype.create = function (array) {}; | |
module.exports = Storage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment