Comments (7)
@SamuelColacchia Thank you for using Morphism
and bringing this feature on the table. I was thinking about having an async
interface on Morphism
for several purposes (parallelization, async transformations...). It might be a good start.
My first thought was to have an .async
property available on morphism
like:
const customerSchema = {
firstname: "firstname",
lastname: "lastname",
email: "email",
group: {
path: "group",
fn: async value => {
const res = await callSomeService(value);
return res.data;
}
}
};
const result = await morphism.async(customerSchema, input)
// ==>
// {
// "firstname": "somefirstname",
// "lastname": "somelastname",
// "email": "[email protected]",
// "group": "somegroup"
// }
Mostly to keep the backward compatibility on the synchronous interface and provide the appropriate typing with TypeScript.
What do you think about this implementation ?
from morphism.
@emyann That seems like it would be a good solution to the problem. Thinking it over in my head it would require the caller of morphism to explicitly want to wait for a async request, which I think is a good approach.
from morphism.
@SamuelColacchia Awesome! Thank you for your feedback, I'm going to schedule this feature on the next
branch as a beta feature. I'll get back to you for testing purposes if you're ok with it :)
from morphism.
@emyann Sounds good to me.
from morphism.
@emyann Hi, thanks for the library, it's nice and compact! How does the feature live? :)
from morphism.
@kirsar Thank you for the feedback! I'm actively working on a big chunk of the library which is Data Validation
that should land soon on the beta
branch (https://github.com/nobrainr/morphism/releases)
Working on that make me realize that I needed to support async validations also, so I'm ideating this async part of morphism
but I do want to have a clear separation between side effects and the actions of transforming the data itself, that in my opinion should stay as pure as possible.
I'll likely come up by the end of this month with a design on how I envision this in Morphism
, and in the meantime I would love to hear about your use-case with that feature if you're interested 🙂
from morphism.
Thanks for reply.
My case is very simple: I need to talk with 3rd party via some amqp and use morphism to map 'my' entities to 'their' commands / events.
And I want to separate mapping config (schema) away from other complexity, but sometimes I need to make async calls to db to reconstruct entity from event (3rd party is not under my control), like:
{
id: 'id',
stateId: event => (await stateRepo.getByCode(event.state)).id,
}
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.