MCPcopy Create free account
hub / github.com/Effect-TS/effect / acceptsNull

Function acceptsNull

packages/tools/ai-codegen/src/Generator.ts:410–431  ·  view source on GitHub ↗
(js: JsonSchema.JsonSchema, seen = new Set<string>())

Source from the content-addressed store, hash-verified

408 // Prove nullability through type constraints, references, allOf and anyOf.
409 // Other constraints (notably enum and oneOf) can exclude null despite a nullable type.
410 const acceptsNull = (js: JsonSchema.JsonSchema, seen = new Set<string>()): boolean => {
411 if (Predicate.isString(js.$ref)) {
412 if (!Object.keys(js).every((key) => key === "$ref" || isAnnotation(key))) return false
413 const key = definitionKey(js.$ref)
414 if (key === undefined || seen.has(key)) return false
415 const definition = resolve(key)
416 if (definition === undefined) return false
417 seen.add(key)
418 const out = acceptsNull(definition, seen)
419 seen.delete(key)
420 return out
421 }
422 if (
423 !Object.keys(js).every((key) => objectKeys.has(key) || key === "allOf" || key === "anyOf" || isAnnotation(key))
424 ) {
425 return false
426 }
427 return (js.type === undefined || js.type === "null" || isStringArray(js.type) && js.type.includes("null")) &&
428 (!Array.isArray(js.allOf) ||
429 js.allOf.every((member) => Predicate.isObject(member) && acceptsNull(member, seen))) &&
430 (!Array.isArray(js.anyOf) || js.anyOf.some((member) => Predicate.isObject(member) && acceptsNull(member, seen)))
431 }
432
433 const prepare = (js: JsonSchema.JsonSchema): JsonSchema.JsonSchema =>
434 rewriteNot(rewriteConditional(rewriteNullable(js, acceptsNull)))

Callers 1

rewriteNullableFunction · 0.70

Calls 9

isAnnotationFunction · 0.85
definitionKeyFunction · 0.85
keysMethod · 0.80
someMethod · 0.80
isStringArrayFunction · 0.70
hasMethod · 0.65
addMethod · 0.65
deleteMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected