A small typescript library for implementing patterns "domain driven design" and "data mapper"
A small TypeScript library with great features:
- Placing the project's primary focus on the core domain and domain logic
- Basing complex designs on a model of the domain
- The interface of an object conforming to this pattern would include functions such as Create, Read, Update, and Delete, that operate on objects that represent domain entity types in a data store.
- A Data Mapper is a Data Access Layer that performs bidirectional transfer of data between a persistent data store (often a REST API) and an in-memory data representation (the domain layer). The goal of the pattern is to keep the in-memory representation and the persistent data store independent of each other and the data mapper itself.
- The layer is composed of one or more mappers (or Data Access Objects), performing the data transfer. Mapper implementations vary in scope. Generic mappers will handle many different domain entity types, dedicated mappers will handle one or a few.
- Initiating a creative collaboration between technical and domain experts to iteratively refine a conceptual model that addresses particular domain problems
Install
package.json
npm
npm i data-mapper-core
Import
;
Global settings
RemoteDataMapperbaseURL = "http://localhost";
For example, in Vue project
; const baseURL = processenvVUE_APP_BASE_URL;RemoteDataMapperbaseURL = baseURL; router store ;
Example
For example you have REST API endpoint
GET /users
Code 200
Response:
GET /users/GWashington
Code 200
Response:
POST /users/GWashington
Code 201
Response:
PUT /users/GWashington
Code 200
Response:
DELETE /users/GWashington
Code 200
Response:
OK! You can make a domain model for a user like this:
;
And then you can make a data mapper class. It will help you extract data from the API into memory and abstract from the data store that you don't control:
;;
Test GET web method for resources
;;
Test GET web method for single resource
;;
Test DELETE web method
;;
Test POST web method for new resource
;;
It's very simple! I am waiting for your feedback on the mail anton.gorinenko@gmail.com ;)