Understanding the Use of `default` for Undefined Environment Variables
hey guys, trying to validate an environment but seems i'm not understanding how
my code:
am getting this:
defaultdefault is supposed to work, which i thought i could use for undefined env variables.my code:
const { PG_HOST, PG_PORT, PG_DATABASE, PG_USERNAME, PG_PASSWORD, PG_USE_SSL } =
Schema.parseSync(
Schema.struct({
PG_HOST: Schema.string.pipe(Schema.default('db')),
PG_PORT: Schema.int()(Schema.NumberFromString).pipe(Schema.default(5432)),
PG_DATABASE: Schema.string.pipe(Schema.default('postgres')),
PG_USERNAME: Schema.string.pipe(Schema.default('postgres')),
PG_PASSWORD: Schema.string.pipe(Schema.default('topsecret')),
PG_USE_SSL: BooleanFromString.pipe(Schema.default(true)),
})
)(process.env);const { PG_HOST, PG_PORT, PG_DATABASE, PG_USERNAME, PG_PASSWORD, PG_USE_SSL } =
Schema.parseSync(
Schema.struct({
PG_HOST: Schema.string.pipe(Schema.default('db')),
PG_PORT: Schema.int()(Schema.NumberFromString).pipe(Schema.default(5432)),
PG_DATABASE: Schema.string.pipe(Schema.default('postgres')),
PG_USERNAME: Schema.string.pipe(Schema.default('postgres')),
PG_PASSWORD: Schema.string.pipe(Schema.default('topsecret')),
PG_USE_SSL: BooleanFromString.pipe(Schema.default(true)),
})
)(process.env);am getting this:
core: FAIL src/lib/core.test.ts [ src/lib/core.test.ts ]
core: Error: error(s) found
core: └─ ["PG_HOST"]
core: └─ is missing
core: ❯ ../../node_modules/@effect/schema/Parser/dist/effect-schema-Parser.esm.js:33:13
core: 31| const getEffect = (ast, isDecoding) => {
core: 32| const parser = goMemo(ast, isDecoding);
core: 33| return (input, options) => parser(input, {
core: | ^
core: 34| ...options,
core: 35| isEffectAllowed: true
core: ❯ src/lib/core.test.ts:27:3core: FAIL src/lib/core.test.ts [ src/lib/core.test.ts ]
core: Error: error(s) found
core: └─ ["PG_HOST"]
core: └─ is missing
core: ❯ ../../node_modules/@effect/schema/Parser/dist/effect-schema-Parser.esm.js:33:13
core: 31| const getEffect = (ast, isDecoding) => {
core: 32| const parser = goMemo(ast, isDecoding);
core: 33| return (input, options) => parser(input, {
core: | ^
core: 34| ...options,
core: 35| isEffectAllowed: true
core: ❯ src/lib/core.test.ts:27:3