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

Method evaluateConfiguration

ark/aot/precompile.ts:7687–7758  ·  view source on GitHub ↗
(
		call: CallExpression,
		module: SourceModule,
		modules: string[]
	)

Source from the content-addressed store, hash-verified

7685 }
7686
7687 private evaluateConfiguration(
7688 call: CallExpression,
7689 module: SourceModule,
7690 modules: string[]
7691 ): Pick<Configuration, "problem" | "reasons" | "hint"> & { value: unknown } {
7692 // the build applies it before any site, so it must run once at load
7693 if (!runsOnceAtLoad(call)) {
7694 return {
7695 value: undefined,
7696 problem:
7697 "configure() must be called once, unconditionally, at the config module's top level",
7698 reasons: []
7699 }
7700 }
7701 const argument = call.arguments[0]
7702 if (!argument) return { value: undefined, problem: undefined, reasons: [] }
7703 const value = this.interpreter.evaluateSite(
7704 createSiteState(argument, module)
7705 )
7706 const dynamic = rejectionOf(value)
7707 const result = dynamic ? chainOf(dynamic) : []
7708 const objects = new Set<unknown>()
7709 const addReason = (reason: string) =>
7710 result.includes(reason) || result.push(reason)
7711 const visit = (o: unknown) => {
7712 if (typeof o !== "object" || o === null || objects.has(o)) return
7713 objects.add(o)
7714 if (o instanceof ModuleNamespace) {
7715 result.push(
7716 "a namespace import used as a value is not in the static subset: import what it exports by name, or declare an object it exports in the call"
7717 )
7718 }
7719 if (!isPlainContainer(o)) return
7720 for (const k of Reflect.ownKeys(o)) {
7721 const v = Reflect.get(o, k)
7722 const standIn = this.standInOf(v)
7723 if (
7724 k === "description" &&
7725 standIn &&
7726 !(standIn.closure && staticBodyOf(standIn.closure.node))
7727 ) {
7728 addReason(
7729 `the description writer at ${standIn.module.positionOf(standIn.node)} must be a static helper, since arktype calls it while defining types`
7730 )
7731 }
7732 // only registered symbols match between the build and the program
7733 if (typeof k === "symbol" && Symbol.keyFor(k) === undefined) {
7734 const [node, origin] = this.interpreter.sourcesBySymbol.get(k) ?? [
7735 call,
7736 module
7737 ]
7738 addReason(
7739 `the symbol key ${String(k)} at ${origin.positionOf(node)} must be a string or one Symbol.for() returns, since the runtime can't match another with the build's`
7740 )
7741 }
7742 visit(v)
7743 }
7744 }

Callers 2

applyConfigurationMethod · 0.95
checkConfigurationMethod · 0.95

Calls 10

writeReasonsInMethod · 0.95
runsOnceAtLoadFunction · 0.90
createSiteStateFunction · 0.90
rejectionOfFunction · 0.90
chainOfFunction · 0.90
evaluateSiteMethod · 0.80
configurationOfMethod · 0.80
snippetOfMethod · 0.80
visitFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected