MCPcopy
hub / github.com/arktypeio/arktype / constructor

Function constructor

ark/schema/scope.ts:266–346  ·  view source on GitHub ↗
(
		/** The set of names defined at the root-level of the scope mapped to their
		 * corresponding definitions.**/
		def: Record<string, unknown>,
		config?: ArkSchemaScopeConfig
	)

Source from the content-addressed store, hash-verified

264 readonly intrinsic: Omit<typeof $ark.intrinsic, `json${string}`>
265
266 constructor(
267 /** The set of names defined at the root-level of the scope mapped to their
268 * corresponding definitions.**/
269 def: Record<string, unknown>,
270 config?: ArkSchemaScopeConfig
271 ) {
272 this.config = mergeConfigs($ark.config, config)
273
274 this.resolvedConfig = mergeConfigs($ark.resolvedConfig, config)
275
276 this.name =
277 this.resolvedConfig.name ??
278 `anonymousScope${Object.keys(scopesByName).length}`
279 if (this.name in scopesByName)
280 throwParseError(`A Scope already named ${this.name} already exists`)
281 scopesByName[this.name] = this
282
283 const aliasEntries = Object.entries(def).map(entry =>
284 this.preparseOwnAliasEntry(...entry)
285 )
286
287 for (const [k, v] of aliasEntries) {
288 let name = k
289 if (k[0] === "#") {
290 name = k.slice(1)
291 if (name in this.aliases)
292 throwParseError(writeDuplicateAliasError(name))
293 this.aliases[name] = v
294 } else {
295 if (name in this.aliases) throwParseError(writeDuplicateAliasError(k))
296 this.aliases[name] = v
297 this.exportedNames.push(name)
298 }
299 if (
300 !hasArkKind(v, "module") &&
301 !hasArkKind(v, "generic") &&
302 !isThunk(v)
303 ) {
304 const preparsed = this.preparseOwnDefinitionFormat(v, { alias: name })
305 this.resolutions[name] =
306 hasArkKind(preparsed, "root") ?
307 this.bindReference(preparsed)
308 : this.createParseContext(preparsed).id
309 }
310 }
311
312 // reduce union of all possible values reduces to unknown
313 rawUnknownUnion ??= this.node(
314 "union",
315 {
316 branches: [
317 "string",
318 "number",
319 "object",
320 "bigint",
321 "symbol",
322 { unit: true },
323 { unit: false },

Callers

nothing calls this directly

Calls 10

mergeConfigsFunction · 0.90
throwParseErrorFunction · 0.90
hasArkKindFunction · 0.90
isThunkFunction · 0.90
flatMorphFunction · 0.90
writeDuplicateAliasErrorFunction · 0.85
nodeMethod · 0.80
mapMethod · 0.65
preparseOwnAliasEntryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…