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

Class InternalScope

ark/type/scope.ts:544–725  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

542}
543
544export class InternalScope<$ extends {} = {}> extends BaseScope<$> {
545 get ambientAttachments(): Ark.boundTypeAttachments<$> | undefined {
546 if (
547 !$arkTypeRegistry.typeAttachments ||
548 this.scopeConfig?.ambient !== undefined
549 )
550 return
551 return this.memo(
552 "ambientAttachments",
553 flatMorph(Object.keys($arkTypeRegistry.typeAttachments), (_, k) => [
554 k,
555 this.type[k as never]
556 ]) as never
557 )
558 }
559
560 private keywordConfigOf(qualifiedName: string): TypeMeta | undefined {
561 const { keywords } = this.cfg
562 return hasOwn(keywords, qualifiedName) ? keywords[qualifiedName] : undefined
563 }
564
565 protected preparseEntry(alias: string, def: unknown): AliasDefEntry {
566 const firstParamIndex = alias.indexOf("<")
567 if (firstParamIndex === -1) {
568 if (hasArkKind(def, "module") || hasArkKind(def, "generic"))
569 return [alias, def]
570
571 const qualifiedName =
572 this.name === "ark" ? alias
573 : alias === "root" ? this.name
574 : `${this.name}.${alias}`
575
576 const configured = (def: unknown) => {
577 const config = this.keywordConfigOf(qualifiedName)
578 return config ? ([def, "@", config] satisfies TupleExpression) : def
579 }
580
581 if (!isThunk(def)) return [alias, configured(def)]
582 // a thunk reads its config when called, so ark doesn't fix it
583 return [
584 alias,
585 () => {
586 const resolution = def()
587 if (hasArkKind(resolution, "generic")) return resolution
588 return configured(resolution)
589 }
590 ]
591 }
592
593 if (alias[alias.length - 1] !== ">") {
594 throwParseError(
595 `'>' must be the last character of a generic declaration in a scope`
596 )
597 }
598
599 const name = alias.slice(0, firstParamIndex)
600 if (hasArkKind(def, "generic"))
601 throwParseError(writeParameterizedGenericKeyMessage(name))

Callers

nothing calls this directly

Calls 10

enumValuesFunction · 0.90
unitsMethod · 0.80
nodeMethod · 0.80
reduceMethod · 0.80
exportMethod · 0.80
mapMethod · 0.65
andMethod · 0.65
mergeMethod · 0.65
finMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected