MCPcopy Create free account
hub / github.com/Effect-TS/effect / schema

Function schema

packages/effect/src/Config.ts:877–906  ·  view source on GitHub ↗
(codec: Schema.ConstraintCodec<T, unknown>, path?: string | ConfigProvider.Path)

Source from the content-addressed store, hash-verified

875 * @since 4.0.0
876 */
877export function schema<T>(codec: Schema.ConstraintCodec<T, unknown>, path?: string | ConfigProvider.Path): Config<T> {
878 const codecStringTree = Schema.toCodecStringTree(codec)
879 const encodedAst = SchemaAST.toEncoded(codecStringTree.ast)
880 const decodeCursor = SchemaParser.decodeUnknownEffect(
881 Schema.make<Schema.Codec<T, ConfigCursor>>(toConfigCursorAST(codecStringTree.ast))
882 )
883 const localPath = typeof path === "string" ? [path] : path ?? []
884 return make((provider, pathPrefix) => {
885 const fullPath = [...pathPrefix, ...localPath]
886 return catchSourceError(loadCursor(provider, fullPath), false).pipe(
887 Effect.flatMapEager((cursor) => {
888 const hasInput = hasProviderInput(encodedAst, cursor.node)
889 return catchSourceError(
890 decodeCursor(cursor).pipe(
891 Effect.mapEager((value) => resolved(value, hasInput)),
892 Effect.catchEager((issue) => {
893 const error = new ConfigError(
894 new Schema.SchemaError(fullPath.length > 0 ? new SchemaIssue.Pointer(fullPath, issue) : issue)
895 )
896 return hasInput
897 ? Effect.fail(evaluationFailure(error, true))
898 : Effect.succeed(absent(error))
899 })
900 ),
901 hasInput
902 )
903 })
904 )
905 })
906}
907
908/** @internal */
909export const TrueValues = Schema.Literals(["true", "yes", "on", "1", "y"])

Callers 15

stringFunction · 0.70
nonEmptyStringFunction · 0.70
numberFunction · 0.70
finiteFunction · 0.70
intFunction · 0.70
literalFunction · 0.70
literalsFunction · 0.70
booleanFunction · 0.70
durationFunction · 0.70
portFunction · 0.70
logLevelFunction · 0.70
redactedFunction · 0.70

Calls 12

catchSourceErrorFunction · 0.85
loadCursorFunction · 0.85
hasProviderInputFunction · 0.85
evaluationFailureFunction · 0.85
absentFunction · 0.85
makeFunction · 0.70
resolvedFunction · 0.70
makeMethod · 0.65
pipeMethod · 0.65
toCodecStringTreeMethod · 0.45
failMethod · 0.45
succeedMethod · 0.45

Tested by 1

assertMemoizedFunction · 0.40