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

Function configureSchema

ark/schema/config.ts:242–285  ·  view source on GitHub ↗
(config: ArkSchemaConfig)

Source from the content-addressed store, hash-verified

240}
241
242export const configureSchema = (config: ArkSchemaConfig): ArkSchemaConfig => {
243 assertNoProblemConfig(config)
244 if ("clone" in config) throwParseError(removedCloneMessage)
245 // a misspelled option would otherwise be kept and never read
246 for (const k in config) {
247 if (isNodeKind(k) || hasOwn(optionNames, k)) continue
248 const nearest = nearestOptionTo(k)
249 throwParseError(
250 writeUnknownConfigOptionMessage(k) +
251 (nearest ? `. Did you mean '${nearest}'?` : "")
252 )
253 }
254 // as is another library's word for one, like "strip"
255 if (
256 config.onUndeclaredKey !== undefined &&
257 !hasOwn(undeclaredKeyBehaviors, config.onUndeclaredKey)
258 ) {
259 throwParseError(
260 writeInvalidUndeclaredKeyBehaviorMessage(config.onUndeclaredKey)
261 )
262 }
263 if (config.locale !== undefined && !hasDomain(config.locale, "object"))
264 throwParseError(writeInvalidLocaleMessage(config.locale))
265 const merged = mergeConfigs($ark.config, copyConfig(config))
266 if ($ark.cfg) {
267 // a config file evaluated again, as after a test runner resets modules,
268 // can reapply what's set, which changes nothing
269 if (!isSameConfig(merged, $ark.config)) {
270 const frozenBy = $ark.cfgFrozenBy
271 let firstType: string | undefined
272 if (typeof frozenBy === "function") {
273 try {
274 firstType = frozenBy()
275 } catch {
276 firstType = undefined
277 }
278 } else firstType = frozenBy
279 return throwParseError(writeConfigureAfterTypeMessage(firstType))
280 }
281 } else Object.assign($ark.config, merged)
282 // what was passed, as a precompiled program's configure() returns, rather
283 // than $ark.config, whose writes would skip this validation
284 return config
285}
286
287/** $ark.config merged over base, with its static locale */
288export const resolveGlobalConfig = (base: ResolvedConfig): ResolvedConfig => {

Callers 2

testSchemaFirst.tsFile · 0.90
parse.test.tsFile · 0.90

Calls 13

throwParseErrorFunction · 0.90
isNodeKindFunction · 0.90
hasOwnFunction · 0.90
hasDomainFunction · 0.90
copyConfigFunction · 0.90
isSameConfigFunction · 0.90
assertNoProblemConfigFunction · 0.85
nearestOptionToFunction · 0.85

Tested by

no test coverage detected