MCPcopy Create free account
hub / github.com/effect-app/libs / handlePropertySignature

Function handlePropertySignature

packages/vue/src/form.ts:108–207  ·  view source on GitHub ↗
(
  propertySignature: S.AST.PropertySignature
)

Source from the content-addressed store, hash-verified

106 }
107
108function handlePropertySignature(
109 propertySignature: S.AST.PropertySignature
110):
111 | NestedFieldInfo<Record<PropertyKey, any>>
112 | FieldInfo<any>
113 | UnionFieldInfo<(NestedFieldInfo<Record<PropertyKey, any>> | FieldInfo<any>)[]>
114 | DiscriminatedUnionFieldInfo<Record<PropertyKey, any>>
115{
116 const schema = S.make(propertySignature.type)
117
118 if (S.AST.isDeclaration(schema.ast)) {
119 const tl = getObjectsAST(schema.ast)
120 return tl
121 ? handlePropertySignature(
122 new S.AST.PropertySignature(
123 propertySignature.name,
124 tl
125 )
126 )
127 : buildFieldInfo(propertySignature)
128 }
129
130 switch (schema.ast._tag) {
131 case "Objects": {
132 return buildFieldInfoFromFieldsRoot(
133 schema as S.Codec<Record<PropertyKey, any>>
134 )
135 }
136 case "Union": {
137 const allTypeLiterals = schema.ast.types.every(getObjectsAST)
138
139 if (allTypeLiterals) {
140 const members = schema
141 .ast
142 .types
143 .map((elAst) =>
144 // syntehtic property signature as if each union member were the only member
145 new S.AST.PropertySignature(
146 propertySignature.name,
147 elAst
148 )
149 )
150 .flatMap((ps) => {
151 // try to retrieve the _tag literal to set _infoTag later
152 const typeLiteral = getObjectsAST(ps.type)
153
154 const tagPropertySignature = typeLiteral?.propertySignatures.find((_) => _.name === "_tag")
155 // unwrap single-element Union to Literal (S.Struct({ _tag: S.Literal("x") }) wraps as Union([Literal("x")]))
156 const tagType = tagPropertySignature
157 ? S.AST.isUnion(tagPropertySignature.type)
158 && tagPropertySignature.type.types.length === 1
159 && S.AST.isLiteral(tagPropertySignature.type.types[0]!)
160 ? tagPropertySignature.type.types[0]
161 : tagPropertySignature.type
162 : undefined
163 const tagLiteral = tagType
164 && S.AST.isLiteral(tagType)
165 && typeof tagType.literal === "string"

Callers 1

Calls 5

getObjectsASTFunction · 0.85
buildFieldInfoFunction · 0.85
makeMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…