MCPcopy
hub / github.com/ajv-validator/ajv / refValidateCode

Function refValidateCode

lib/standalone/index.ts:68–83  ·  view source on GitHub ↗
(n: ValueScopeName)

Source from the content-addressed store, hash-verified

66 return s.evaluated ? _`${code}${s.validateName}.evaluated = ${s.evaluated};${_n}` : code
67
68 function refValidateCode(n: ValueScopeName): Code | undefined {
69 const vRef = n.value?.ref
70 if (n.prefix === "validate" && typeof vRef == "function") {
71 const v = vRef as AnyValidateFunction
72 return validateCode(usedValues, v.source)
73 } else if ((n.prefix === "root" || n.prefix === "wrapper") && typeof vRef == "object") {
74 const {validate, validateName} = vRef as SchemaEnv
75 if (!validateName) throw new Error("ajv internal error")
76 const def = ajv.opts.code.es5 ? varKinds.var : varKinds.const
77 const wrapper = _`${def} ${n} = {validate: ${validateName}};`
78 if (usedState(validateName) === UsedValueState.Started) return wrapper
79 const vCode = validateCode(usedValues, validate?.source)
80 return _`${wrapper}${_n}${vCode}`
81 }
82 return undefined
83 }
84
85 function usedState(name: ValueScopeName): UsedValueState | undefined {
86 return usedValues[name.prefix]?.get(name)

Callers

nothing calls this directly

Calls 3

_Function · 0.90
validateCodeFunction · 0.85
usedStateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…