is there a way to have an async morph?

const formSchema = type({
appId: 'string',
nodeId: 'string',
id: type('string | undefined').pipe((v) => v ?? nanoid()),
title: type('string.trim').pipe((title) => encryptWithUserKeys(title))
});
const formSchema = type({
appId: 'string',
nodeId: 'string',
id: type('string | undefined').pipe((v) => v ?? nanoid()),
title: type('string.trim').pipe((title) => encryptWithUserKeys(title))
});
encryptWIthUserKeys is an async function
17 Replies
ssalbdivad
ssalbdivad•2w ago
Other than handling it as a promise on the output object, no. Something I've thought a bit about but it seems it would add a huge amount of complexity to the type system for somewhat marginal benefit? Would be interested in uses cases where it feels really impactful though and somewhat open to reconsidering in the long term
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
got it, makes sense, any recommendations you would have for my usecase, would you recommend to just encrypt it before passing to the validator? or afterwards myself ig
ssalbdivad
ssalbdivad•2w ago
Probably after? I guess it depends a bit on the situation but usually after
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
thanks, appreciate the quick reply
ssalbdivad
ssalbdivad•2w ago
Taking the next couple days off so good timing on the questions 😅 There's some other folks in here who may able to chip in but yeah tough to get answers otherwise on my intent for some missing feature or similar
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
yes, I think a lof these questions could be handled better in docs, for example ctx.reject isn't documented at all afaik and maybe an FAQ for the async morph stuff
ssalbdivad
ssalbdivad•2w ago
Yeah you should have seen the docs a couple months ago though already a lot better. Trying to keep logging issues in the backlog to continue improving and add new functionality. Definitely an area I'd love contributions if you're so inclined!
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
is there a getting started for how to contribute? maybe even doc specific
ssalbdivad
ssalbdivad•2w ago
There's a contributing guide yeah but it's not really doc specific. Broadly speaking though it's pretty easy to see how most of the repo works and to add docs similar to what else is there. I'd focus on stuff that is relatively objective and narrow (e.g. an faq on async validators or maybe more on reject) rather than high-level overviews of concepts which might be more nuanced. https://github.com/arktypeio/arktype/blob/main/.github/CONTRIBUTING.md
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
thanks is there an issue where doc stuff is assigned or tracked? so multiple people don't try to write docs for the same thing
ssalbdivad
ssalbdivad•2w ago
You can create a GitHub issue for it which would be helpful mostly for me for tracking purposes, but you might be overestimating the number of people trying to write docs for the project 😛
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
got it
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
created a PR, can also create accompanying issue if would help https://github.com/arktypeio/arktype/pull/1302
GitHub
docs: document current stance on async morphs by vanillacode314 · P...
Document that async morphs are not supported and it is intentional since the use cases aren't compelling enough yet and it would add a lot of complexity to the codebase
ssalbdivad
ssalbdivad•2w ago
Great, will take a look at this on Tuesday, thank you!
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
will try later to document ctx.reject but don't understand it myself enough XD, I think it's a discriminated union but the autocomplete doesn't help at all lol
ssalbdivad
ssalbdivad•2w ago
Yeah it's discriminated on code TS doesn't always give great hints for that kind of thing though depending on what keys you include first
Raqueebuddin Aziz
Raqueebuddin AzizOP•2w ago
makes sense

Did you find this page helpful?