MCPcopy Index your code
hub / github.com/Effect-TS/effect / mergeRefinements

Function mergeRefinements

packages/effect/src/JSONSchema.ts:552–578  ·  view source on GitHub ↗
(from: any, jsonSchema: any, ast: AST.AST)

Source from the content-addressed store, hash-verified

550}
551
552const mergeRefinements = (from: any, jsonSchema: any, ast: AST.AST): any => {
553 const out: any = { ...from, ...getJsonSchemaAnnotations(ast), ...jsonSchema }
554 out.allOf ??= []
555
556 const handle = (name: string, filter: (i: any) => boolean) => {
557 if (name in jsonSchema && name in from) {
558 out.allOf.unshift({ [name]: from[name] })
559 out.allOf = out.allOf.filter(filter)
560 }
561 }
562
563 handle("minLength", (i) => i.minLength > jsonSchema.minLength)
564 handle("maxLength", (i) => i.maxLength < jsonSchema.maxLength)
565 handle("pattern", (i) => i.pattern !== jsonSchema.pattern)
566 handle("minItems", (i) => i.minItems > jsonSchema.minItems)
567 handle("maxItems", (i) => i.maxItems < jsonSchema.maxItems)
568 handle("minimum", (i) => i.minimum > jsonSchema.minimum)
569 handle("maximum", (i) => i.maximum < jsonSchema.maximum)
570 handle("exclusiveMinimum", (i) => i.exclusiveMinimum > jsonSchema.exclusiveMinimum)
571 handle("exclusiveMaximum", (i) => i.exclusiveMaximum < jsonSchema.exclusiveMaximum)
572 handle("multipleOf", (i) => i.multipleOf !== jsonSchema.multipleOf)
573
574 if (out.allOf.length === 0) {
575 delete out.allOf
576 }
577 return out
578}
579
580type GoOptions = {
581 readonly getRef: (id: string) => string

Callers 1

goFunction · 0.85

Calls 2

getJsonSchemaAnnotationsFunction · 0.85
handleFunction · 0.70

Tested by

no test coverage detected