MCPcopy Create free account
hub / github.com/arktypeio/arktype / addConstraints

Function addConstraints

ark/schema/parseSchema.ts:465–488  ·  view source on GitHub ↗
(
	input: dict,
	kind: ConstraintKind,
	schema: unknown,
	$: BaseScope
)

Source from the content-addressed store, hash-verified

463 : throwParseError(writeInvalidSchemaMessage(schema))
464
465const addConstraints = (
466 input: dict,
467 kind: ConstraintKind,
468 schema: unknown,
469 $: BaseScope
470): void => {
471 const items = isArray(schema) ? schema : [schema]
472 for (const item of items) {
473 const constraint: BaseNode = parseNodeSchema(kind, item, $)
474 // a constraint reducing to a root, like unknown for minLength: 0, is trivially satisfied
475 if (constraint.isRoot()) continue
476 const ck = constraint.kind
477 if (constraint.canStack()) {
478 input[ck] =
479 input[ck] ? [...(input[ck] as BaseNode[]), constraint] : [constraint]
480 } else if (input[ck]) {
481 const merged = (input[ck] as BaseConstraint).intersect(
482 constraint as BaseConstraint
483 )
484 if (merged instanceof Disjoint) return merged.throw()
485 if (merged) input[ck] = merged
486 } else input[ck] = constraint
487 }
488}
489
490const isExpandedSequenceSchema = (
491 schema: SequenceSchema

Callers 1

parseSchema.tsFile · 0.85

Calls 3

parseNodeSchemaFunction · 0.85
intersectMethod · 0.80
throwMethod · 0.65

Tested by

no test coverage detected