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

Function applyNullable

packages/effect/src/JsonSchema.ts:994–1011  ·  view source on GitHub ↗
(node: Record<string, unknown>)

Source from the content-addressed store, hash-verified

992}
993
994function applyNullable(node: Record<string, unknown>): Record<string, unknown> {
995 // enum widening
996 if (Array.isArray(node.enum)) {
997 return widenType({
998 ...node,
999 enum: node.enum.includes(null) ? node.enum : [...node.enum, null]
1000 })
1001 }
1002
1003 // type widening
1004 if (node.type !== undefined) return widenType(node)
1005
1006 // const === null
1007 if (node.const === null) return node
1008
1009 // fallback
1010 return { anyOf: [node, { type: "null" }] }
1011}
1012
1013function widenType(node: Record<string, unknown>): Record<string, unknown> {
1014 const t = node.type

Callers 1

Calls 1

widenTypeFunction · 0.85

Tested by

no test coverage detected