MCPcopy
hub / github.com/Effect-TS/effect / getTemplateLiteralParserCoercedElement

Function getTemplateLiteralParserCoercedElement

packages/effect/src/Schema.ts:885–917  ·  view source on GitHub ↗
(encoded: Schema.Any, schema: Schema.Any)

Source from the content-addressed store, hash-verified

883}
884
885function getTemplateLiteralParserCoercedElement(encoded: Schema.Any, schema: Schema.Any): Schema.Any | undefined {
886 const ast = encoded.ast
887 switch (ast._tag) {
888 case "Literal": {
889 const literal = ast.literal
890 if (!Predicate.isString(literal)) {
891 const s = String(literal)
892 return transform(Literal(s), schema, {
893 strict: true,
894 decode: () => literal,
895 encode: () => s
896 })
897 }
898 break
899 }
900 case "NumberKeyword":
901 return compose(NumberFromString, schema)
902 case "Union": {
903 const members: Array<Schema.Any> = []
904 let hasCoercions = false
905 for (const member of ast.types) {
906 const schema = make(member)
907 const encoded = encodedSchema(schema)
908 const coerced = getTemplateLiteralParserCoercedElement(encoded, schema)
909 if (coerced) {
910 hasCoercions = true
911 }
912 members.push(coerced ?? schema)
913 }
914 return hasCoercions ? compose(Union(...members), schema) : schema
915 }
916 }
917}
918
919/**
920 * @category template literal

Callers 1

TemplateLiteralParserFunction · 0.85

Calls 7

StringInterface · 0.85
encodedSchemaFunction · 0.85
transformInterface · 0.70
LiteralFunction · 0.70
composeFunction · 0.70
makeFunction · 0.70
UnionFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…