Comments (10)
Awesome, this is a really nice lib.
Probably way outside the scope of what this library is for but it would be cool to be able to output the schema transformations on some sort of diagram. Perhaps an online tool or CLI that outputs to something like d3.js.
from morphism.
@davej This is definitely something I had thought about! I really love the idea, I just didn't know if this could be valuable. Thank you a lot for bringing this on the table, I'll add it to the list :)
from morphism.
Might be nice to have easy hooks to sanitize data during mapping. Can currently do this manually with a function mapper, but might be nice to have a more abstract way.
We are not using typescript at the moment unfortunately.
Think of an integration with sanitizers like validator.js
, like express-validator does.
We are using this lib to connect backend services with our internal micro-services, as an ETL-like process. This library is great to map the data, but needs a bit more in the transformation-side.
We are just starting to use it, and I would be happy to help out in the coming months.
from morphism.
@cjancsar This is awesome that you bring this on the table as I'm actually working on the Validation
side of Morphism! This is only available on the next
branch of this library (npm install morphism@next
).
This is not yet ready for production but you can see a sneak peek here:
- https://repl.it/@yrnd1/Morphism-Simple-Validation
- https://repl.it/@yrnd1/Morphism-Validation-Custom-Reporter
- https://repl.it/@yrnd1/Morphism-Validation-Custom-Reporter-And-Formatter
I added some basic string validators here https://github.com/nobrainr/morphism/blob/next/src/validation/validators/StringValidator.ts like min
, max
, length
, alphanum
, regex
and planning to add more in the future.
Is it similar to what you had in mind ?
from morphism.
@emyann yes! That is exactly what I was thinking.
Do the validators have the ability to change the data, or are they read-only, and only throw errors?
Are you re-creating all your own validators? I know you likely don't want to add an external dependency, but the lib might also get more recognition and wide-spread use if it connected to the already-awesome validator.js which has tons of existing validators.
It also has sanitizers, which coerce the incoming value to another format / clean the data. Would also be nice to see that.
For example:
import { morphism, createSchema, Validation, Sanitization, reporter } from 'morphism';
const source = { name: 'Cassandra', id: '14' };
const schema = createSchema({
id: {
fn: (source:any) => source.id,
validation: Validation.isInt(),
sanitization: Sanitization.toInt()
}
});
> output = { name: 'Cassandra', id: 14 }
Pretty basic example, but you get the point.
from morphism.
@cjancsar Yes of course, thank you for offering your help! I'll wrap my head around the integration with 3rd party libraries and prepare the ground for the work. I'll get back to you whenever I start this refactoring.
from morphism.
This looks really nice. I am using the JOLT java library in the backend. For the frontend transformations I consider Morphism. I have one specific requirement: The transformation schema must be expressed in JSON. As far as I understand, that can be done with Morphism, my own code will do the (trivial) parse of the JSON before handing the scheme to Morphism.
from morphism.
@reitsma Thank you for considering using Morphism! I don't see any actual blocker for your use case ? If you're able to parse and revive the functions you might have in your schema, it's going to work straight away.
from morphism.
Awesome!
Do the validators have the ability to change the data, or are they read-only, and only throw errors?
Yes actually it does coerce the value to another format and I wanted to give the user the ability to choose the behavior, but I really love the suggestions you shared (Sanitization, integration with validator.js
). I'll work on making the validation interface more composable so that it would be easy to plug any other validation / sanitization library rather than taking a dependency on a specific library (if some prefer joi over validator.js
it would be possible)
from morphism.
@emyann cool! Let me know if there are any low-hanging requirements and I will try and spend some time helping you out.
from morphism.
Related Issues (20)
- Mocking `morphism` named export HOT 2
- [Question] How to construct an object with projection HOT 3
- [Bug] Inferred types break with certain target types HOT 2
- Spying on morphism with ts-mockito ? HOT 6
- Difference between an object with type and using createSchema HOT 2
- Failing to change types of target schema (TypeScript) HOT 3
- Dealing with undefined source ? HOT 4
- A little help with flattening ? HOT 9
- [Question] Is there an easy way to apply the identity morphism? HOT 4
- A merge method for copying properties with mappings HOT 5
- [Question]: Who is using the Registry to store the mappers ?
- Map array of objects? HOT 1
- Help needed to flatten nest array within a object
- Generics do not work properly with typescript HOT 3
- Morphism playground doesnt work
- Mapping with runtime arguments?
- mapping array without functions
- [Question] Supporting circular references in destination types
- How to map nested types HOT 2
- Still being updated? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from morphism.