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

Method value

lib/compile/codegen/scope.ts:137–156  ·  view source on GitHub ↗
(nameOrPrefix: ValueScopeName | string, value: NameValue)

Source from the content-addressed store, hash-verified

135 }
136
137 value(nameOrPrefix: ValueScopeName | string, value: NameValue): ValueScopeName {
138 if (value.ref === undefined) throw new Error("CodeGen: ref must be passed in value")
139 const name = this.toName(nameOrPrefix) as ValueScopeName
140 const {prefix} = name
141 const valueKey = value.key ?? value.ref
142 let vs = this._values[prefix]
143 if (vs) {
144 const _name = vs.get(valueKey)
145 if (_name) return _name
146 } else {
147 vs = this._values[prefix] = new Map()
148 }
149 vs.set(valueKey, name)
150
151 const s = this._scope[prefix] || (this._scope[prefix] = [])
152 const itemIndex = s.length
153 s[itemIndex] = value.ref
154 name.setValue(value, {property: prefix, itemIndex})
155 return name
156 }
157
158 getValue(prefix: string, keyOrRef: unknown): ValueScopeName | undefined {
159 const vs = this._values[prefix]

Callers 4

compileSchemaFunction · 0.80
scopeValueMethod · 0.80
compileSerializerFunction · 0.80
compileParserFunction · 0.80

Calls 3

toNameMethod · 0.80
getMethod · 0.80
setValueMethod · 0.80

Tested by

no test coverage detected