effect icon indicating copy to clipboard operation
effect copied to clipboard

Add a Schema.config for decoding Configs using a Schema.

Open jessekelly881 opened this issue 1 year ago • 2 comments

What is the problem this feature would solve?

It would be convenient to be able to use a Schema instead one of the built in Config primitives for decoding a Config var.

What is the feature you are proposing to solve the problem?

Add a Schema.config :: (Schema<A, string, R>, name?: string) -> Effect<Config<A>, never, R> function.

What alternatives have you considered?

None.

jessekelly881 avatar Mar 16 '24 17:03 jessekelly881

I think this should wait until schema is part of "effect", as it seems like an api that should be owned by the Config module.

tim-smart avatar Mar 19 '24 21:03 tim-smart

I'm using this at the moment :

import * as S from '@effect/schema/Schema';
import { EmailAddress } from 'my-domain';

 const EmailAddressConfig = flow(
  Config.string,
  Config.validate({
    message: 'Expected a valid EmailAddress',
    validation: S.is(EmailAddress),
  })
);

const AdminEmailAddressConfig = EmailAddressConfig('ADMIN_EMAIL_ADDRESS');

wewelll avatar Apr 25 '24 15:04 wewelll

@vecerek @jessekelly881 impl here, feel free to leave any comments: https://github.com/Effect-TS/effect/pull/2816

gcanti avatar May 22 '24 17:05 gcanti