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

Function encode

ark/schema/shared/codecs.ts:36–54  ·  view source on GitHub ↗
(node: BaseRoot)

Source from the content-addressed store, hash-verified

34 `A morph must have an inverse to be encoded: ${expression}`
35
36export const encode = (node: BaseRoot): BaseRoot => {
37 let encoder = encoders.get(node)
38 if (!encoder) {
39 const isFinal = isResolutionFinal()
40 // discard any check left over from an earlier failed parse
41 if (isFinal) defining(() => {})
42 let raw: BaseRoot
43 try {
44 raw = encoderOf(node)
45 } catch (e) {
46 // discard any check queued for synthetic aliases of a failed encode
47 if (isFinal) defining(() => {})
48 throw e
49 }
50 assertUnchecked()
51 encoders.set(node, (encoder = node.$.fin(raw)))
52 }
53 return encoder
54}
55
56// the decoding graph with each morph inverted
57const encoderOf = (node: BaseRoot): BaseRoot => {

Callers 1

algebra.test.tsFile · 0.90

Calls 7

isResolutionFinalFunction · 0.90
definingFunction · 0.90
assertUncheckedFunction · 0.90
encoderOfFunction · 0.85
getMethod · 0.65
setMethod · 0.45
finMethod · 0.45

Tested by

no test coverage detected