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

Function validateAmbientConfig

ark/schema/scope.ts:247–274  ·  view source on GitHub ↗
(ambient: unknown)

Source from the content-addressed store, hash-verified

245 `ambient.${key} must be a Type, Generic, or Module (was ${printable(actual)})`
246
247const validateAmbientConfig = (ambient: unknown): void => {
248 if (hasArkKind(ambient, "module")) {
249 if (!isInstanceOf(ambient, RootModule))
250 throwParseError(writeForeignArkMessage("ambient"))
251 return
252 }
253 if (
254 typeof ambient !== "object" ||
255 ambient === null ||
256 Array.isArray(ambient) ||
257 !isPlainObjectOrArray(ambient)
258 )
259 throwParseError(writeInvalidAmbientMessage(ambient))
260 for (const [k, v] of Object.entries(ambient)) {
261 if (
262 (hasArkKind(v, "root") && !isInstanceOf(v, BaseRoot)) ||
263 (hasArkKind(v, "module") && !isInstanceOf(v, RootModule)) ||
264 (hasArkKind(v, "generic") && !isInstanceOf(v, GenericRoot))
265 )
266 throwParseError(writeForeignArkMessage(`ambient.${k}`))
267 if (
268 !hasArkKind(v, "root") &&
269 !hasArkKind(v, "module") &&
270 !hasArkKind(v, "generic")
271 )
272 throwParseError(writeInvalidAmbientEntryMessage(k, v))
273 }
274}
275
276export interface ScopeOnlyConfigOptions {
277 name?: string

Callers 1

constructorFunction · 0.85

Calls 7

hasArkKindFunction · 0.90
isInstanceOfFunction · 0.90
throwParseErrorFunction · 0.90
isPlainObjectOrArrayFunction · 0.90
writeForeignArkMessageFunction · 0.85

Tested by

no test coverage detected