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

Function compose

packages/tools/ai-codegen/src/Generator.ts:467–494  ·  view source on GitHub ↗
(js: JsonSchema.JsonSchema)

Source from the content-addressed store, hash-verified

465 }
466
467 const compose = (js: JsonSchema.JsonSchema): JsonSchema.JsonSchema => {
468 // Sibling choices must both hold.
469 const members = [
470 ...(Array.isArray(js.allOf) ? js.allOf : []),
471 ...(Array.isArray(js.anyOf) ? [{ anyOf: js.anyOf }] : []),
472 ...(Array.isArray(js.oneOf) ? [{ oneOf: js.oneOf }] : [])
473 ]
474 const hasOwn = js.properties !== undefined || js.required !== undefined
475 const constraints = members.filter((member) =>
476 !Predicate.isObject(member) || !Object.keys(member).every(isAnnotation)
477 )
478 // Annotation-only members do not require expanding references; the importer attaches their metadata.
479 if ((hasOwn ? 1 : 0) + constraints.length < 2) return js
480 const { allOf: _allOf, anyOf: _anyOf, oneOf: _oneOf, ...rest } = js
481 if (!isPlainObject(rest)) return js
482 const own = pick(rest, (key) => objectKeys.has(key))
483 let part: Part = { _tag: "Object", schema: own }
484 for (const member of members) {
485 const next = toPart(member)
486 const merged: Part | undefined = next === undefined ? undefined : mergeParts(part, next)
487 if (merged === undefined) return js
488 part = merged
489 }
490 const annotations = pick(rest, isAnnotation)
491 return part._tag === "Object"
492 ? { ...annotations, ...part.schema }
493 : { ...annotations, [part.mode]: part.branches }
494 }
495
496 const dropRedundantObjectType = (js: JsonSchema.JsonSchema): JsonSchema.JsonSchema => {
497 if (js.type !== "object") return js

Callers 2

dereferenceFunction · 0.70
makeNormalizerFunction · 0.70

Calls 7

isPlainObjectFunction · 0.85
mergePartsFunction · 0.85
keysMethod · 0.80
pickFunction · 0.70
toPartFunction · 0.70
hasMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected