MCPcopy Create free account
hub / github.com/arktypeio/arktype / pipeEncoder

Function pipeEncoder

ark/schema/shared/codecs.ts:234–254  ·  view source on GitHub ↗
(
	encoder: BaseRoot,
	next: BaseRoot,
	encoderTfs: boolean,
	nextTfs: boolean,
	$: BaseScope
)

Source from the content-addressed store, hash-verified

232}
233
234const pipeEncoder = (
235 encoder: BaseRoot,
236 next: BaseRoot,
237 encoderTfs: boolean,
238 nextTfs: boolean,
239 $: BaseScope
240): BaseRoot => {
241 if (encoder.isUnknown()) return next
242 if (next.isUnknown() || encoder === next) return encoder
243 // a node that only transforms through an alias has alters === false,
244 // so rawPipeOnce would intersect it (and any open synthetic alias)
245 if ((encoderTfs && !encoder.alters) || (nextTfs && !next.alters)) {
246 return encoder.is("morph") ?
247 $.node("morph", {
248 ...encoder.inner,
249 morphs: [...encoder.morphs, next]
250 })
251 : $.node("morph", { morphs: [encoder, next] })
252 }
253 return encoder.rawPipeOnce(next)
254}
255
256// a defaulted key or element is always present in what was decoded
257const requireDefaulted = (inner: Structure.Inner): Structure.Inner => {

Callers 1

invertFunction · 0.85

Calls 2

isMethod · 0.80
nodeMethod · 0.80

Tested by

no test coverage detected