pattern to use for embedded resources with variable fields?
I'm brainstorming how I'd be able to have embedded resources that have variable schemas, lets say I have a SocialMediaAccount resource, and I want an 'adapter_config' column that will be a set of config to integrate with the SocialMediaAccount, i.e: twitter api keys etc
I'm going to implement an adapter pattern type thing that will include validations and a few methods to integrate with the social platform, I'm just wondering how I'd define that column in my resource?
I was thinking of just using a map type - then handling validations etc in a custom change / validation?
10 Replies
then it just saves to jsonb when I save, I'm just wondering if there's a nicer way to do it
could also just KISS and pattern match different functions based on the type of social media account
will encrypt api tokens etc within the jsonb, so will already need a custom changeset to handle that
it would be nice to be able to use an EmbeddedResource and have them automatically swap out based on a column on the SocialMediaAccount resource, I can get a nice DSL to define validations / lifecycles
Have you looked into the new union type?
Sounds like itβs exactly what you want
yup it is
Not that new actually I guess
just opened the docs π
new for me lol
easy to plug in a custom change to encrypt certain values?
Yeah, since the destination type can be an embedded resource
We use the primary actions on the target resource to instantiate things
So you could add a change to the primary create action
easy, so override read to decrypt stuff and create / update to encyrpt
Iβd suggest adding calculations to decrypt
right
makes sense then I just don't load them if I don't actually need to use them
can even get fancy with the new field policies π
assuming they work on calculations?
Yep!