MCPcopy Create free account
hub / github.com/CommE2E/comm / findFirstInputMatchingValidator

Function findFirstInputMatchingValidator

keyserver/src/utils/validation-utils.js:149–212  ·  view source on GitHub ↗
(
  wholeInputValidator: any,
  inputValidatorToMatch: any,
  input: any,
)

Source from the content-addressed store, hash-verified

147}
148
149function findFirstInputMatchingValidator(
150 wholeInputValidator: any,
151 inputValidatorToMatch: any,
152 input: any,
153): any {
154 if (!wholeInputValidator || input === null || input === undefined) {
155 return null;
156 }
157 if (
158 wholeInputValidator === inputValidatorToMatch &&
159 wholeInputValidator.is(input)
160 ) {
161 return input;
162 }
163 if (wholeInputValidator.meta.kind === 'maybe') {
164 return findFirstInputMatchingValidator(
165 wholeInputValidator.meta.type,
166 inputValidatorToMatch,
167 input,
168 );
169 }
170 if (
171 wholeInputValidator.meta.kind === 'interface' &&
172 typeof input === 'object'
173 ) {
174 for (const key in input) {
175 const value = input[key];
176 const validator = wholeInputValidator.meta.props[key];
177 const innerResult = findFirstInputMatchingValidator(
178 validator,
179 inputValidatorToMatch,
180 value,
181 );
182 if (innerResult) {
183 return innerResult;
184 }
185 }
186 }
187 if (wholeInputValidator.meta.kind === 'union') {
188 for (const validator of wholeInputValidator.meta.types) {
189 if (validator.is(input)) {
190 return findFirstInputMatchingValidator(
191 validator,
192 inputValidatorToMatch,
193 input,
194 );
195 }
196 }
197 }
198 if (wholeInputValidator.meta.kind === 'list' && Array.isArray(input)) {
199 const validator = wholeInputValidator.meta.type;
200 for (const value of input) {
201 const innerResult = findFirstInputMatchingValidator(
202 validator,
203 inputValidatorToMatch,
204 value,
205 );
206 if (innerResult) {

Callers 1

checkClientSupportedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected