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

Function _tf

ark/schema/node.ts:1404–1501  ·  view source on GitHub ↗

transforms it and the nodes it holds with mapper, returning null to remove it

(
		mapper: DeepNodeTransformation,
		ctx: DeepNodeTransformContext
	)

Source from the content-addressed store, hash-verified

1402
1403 /** transforms it and the nodes it holds with mapper, returning null to remove it */
1404 protected _tf(
1405 mapper: DeepNodeTransformation,
1406 ctx: DeepNodeTransformContext
1407 ): BaseNode | null {
1408 const $ = ctx.bindScope ?? this.$
1409 const seen = ctx.seen[this.id]
1410 const transformedResolution = seen?.()
1411 if (transformedResolution) return transformedResolution
1412 if (ctx.shouldTf?.(this as never, ctx) === false) return this
1413 if (this.is("alias") && ctx.throughAliases) {
1414 const resolution = this.resolution
1415 if (!ctx.seen[resolution.id]) {
1416 const transformed = resolution._tf(mapper, ctx)
1417 if (!transformed) return transformed
1418 ctx.seen[resolution.id] = () => transformed
1419 }
1420 ctx.synth[resolution.id] ??= this.$.openSynthetic(
1421 ctx.names?.[resolution.id] ??
1422 (resolution.id === ctx.root.id ? undefined : this.expression)
1423 )
1424 return this.$.lazilyResolve(
1425 ctx.seen[resolution.id]! as never,
1426 ctx.synth[resolution.id].id
1427 )
1428 }
1429
1430 let transformedNode: BaseRoot | undefined
1431
1432 ctx.seen[this.id] = () => transformedNode
1433
1434 try {
1435 if (
1436 this.is("structure") &&
1437 this.handlesUndeclared !== ctx.undeclaredHandling
1438 ) {
1439 ctx = {
1440 ...ctx,
1441 undeclaredHandling: this.handlesUndeclared
1442 }
1443 }
1444
1445 const innerWithTransformedChildren = this._tfChildren(mapper, ctx)
1446
1447 const innerWithMeta = Object.assign(innerWithTransformedChildren, {
1448 meta: this.meta
1449 })
1450
1451 // a node with a selected node's id is that node as another object, as an unread
1452 // Type built to a node that already existed is and as one bound to another
1453 // scope is. It's selected too unless the selector's predicate refuses it, as
1454 // one asking for an object does
1455 const selected =
1456 !ctx.selected ||
1457 ctx.selected.includes(this) ||
1458 (ctx.selected.some(node => node.id === this.id) &&
1459 (!ctx.selectedWhere || ctx.selectedWhere(this)))
1460
1461 let transformedInner =

Callers

nothing calls this directly

Calls 6

isNodeFunction · 0.90
isEmptyObjectFunction · 0.90
mapperFunction · 0.85
isMethod · 0.80
nodeMethod · 0.80
_tfMethod · 0.45

Tested by

no test coverage detected