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

Function parseInnerDefinition

ark/type/parser/definition.ts:78–118  ·  view source on GitHub ↗
(
	def: unknown,
	ctx: BaseParseContext
)

Source from the content-addressed store, hash-verified

76const parseCacheSizes = new WeakMap<BaseScope, number>()
77
78export const parseInnerDefinition = (
79 def: unknown,
80 ctx: BaseParseContext
81): InnerParseResult => {
82 if (typeof def === "string") {
83 if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
84 // we can only rely on the cache if there are no contextual
85 // resolutions like "this" or generic args
86 return parseString(def, ctx)
87 }
88 let scopeCache = parseCache.get(ctx.$)
89 if (!scopeCache) {
90 scopeCache = Object.create(null) as Record<string, InnerParseResult>
91 parseCache.set(ctx.$, scopeCache)
92 }
93 if (scopeCache[def]) {
94 $ark.reached?.cached(scopeCache, def)
95 return scopeCache[def]
96 }
97 const mark = $ark.reached?.mark()
98 const result = parseString(def, ctx)
99 const node = isArray(result) ? result[0] : result
100 if (!inProgress.definitions || !node.hasAlias) {
101 scopeCache = parseCache.get(ctx.$) ?? scopeCache
102 if (!(def in scopeCache)) {
103 const size = (parseCacheSizes.get(ctx.$) ?? 0) + 1
104 if (size > maxCachedDefs) {
105 scopeCache = Object.create(null) as Record<string, InnerParseResult>
106 parseCache.set(ctx.$, scopeCache)
107 parseCacheSizes.set(ctx.$, 1)
108 } else parseCacheSizes.set(ctx.$, size)
109 }
110 scopeCache[def] = result
111 $ark.reached?.store(mark, scopeCache, def)
112 }
113 return result
114 }
115 return hasDomain(def, "object") ?
116 parseObject(def, ctx)
117 : throwParseError(writeBadDefinitionTypeMessage(domainOf(def)))
118}
119
120export const parseObject = (def: object, ctx: BaseParseContext): BaseRoot => {
121 const objectKind = objectKindOf(def)

Callers 2

parseOwnMethod · 0.90
parsePropertyFunction · 0.90

Calls 10

parseStringFunction · 0.90
hasDomainFunction · 0.90
throwParseErrorFunction · 0.90
domainOfFunction · 0.90
parseObjectFunction · 0.85
markMethod · 0.80
storeMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected