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

Method constructor

ark/schema/structure/sequence.ts:159–205  ·  view source on GitHub ↗
(...args: ConstructorParameters<typeof BaseConstraint>)

Source from the content-addressed store, hash-verified

157
158export class SequenceNode extends BaseConstraint<Sequence.Declaration> {
159 constructor(...args: ConstructorParameters<typeof BaseConstraint>) {
160 super(...args)
161 this.costly = true
162 // a configured writer runs as its node is created
163 if (
164 this.$.cfg.sequence.description !==
165 $ark.defaultConfig.sequence.description
166 )
167 void this.description
168 if (this.inner.postfix) {
169 if (!this.inner.variadic) throwParseError(postfixWithoutVariadicMessage)
170 if (this.inner.optionals || this.inner.defaultables)
171 throwParseError(postfixAfterOptionalOrDefaultableMessage)
172 }
173 if (this.inner.minVariadicLength && !this.inner.variadic) {
174 throwParseError(
175 "minVariadicLength may not be specified without a variadic element"
176 )
177 }
178 // a set engine adds the length bounds a tuple implies to its intersection,
179 // and the undefined its elements allow without exactOptionalPropertyTypes
180 if (
181 !$ark.sets &&
182 (!this.inner.variadic ||
183 this.inner.prefix ||
184 this.inner.postfix ||
185 this.inner.minVariadicLength ||
186 (this.isLoose && (this.inner.optionals || this.inner.defaultables)))
187 )
188 throwParseError(missingSetEngineMessage)
189 if (this.inner.defaultables) {
190 // a default of undefined would replace undefined with itself
191 for (const [node, value] of this.inner.defaultables) {
192 assertDefaultValueAssignability(
193 this.requiredOf(node),
194 value,
195 null,
196 this
197 )
198 }
199 }
200 // a function default can fail as it's applied, like a morph
201 this.hasMorph ||= !!this.defaultables?.some(
202 ([, defaultValue]) => typeof defaultValue === "function"
203 )
204 this.ctxMorph ||= this.defMorphs.some(morph => morph.length === 2)
205 }
206
207 get implied(): BaseRoot {
208 return $ark.kw.Array.internal

Callers

nothing calls this directly

Calls 3

requiredOfMethod · 0.95
throwParseErrorFunction · 0.90

Tested by

no test coverage detected