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

Function transform

ark/schema/node.ts:1343–1382  ·  view source on GitHub ↗
(
		mapper: mapper,
		opts?: DeepNodeTransformOptions
	)

Source from the content-addressed store, hash-verified

1341 }
1342
1343 transform<mapper extends DeepNodeTransformation>(
1344 mapper: mapper,
1345 opts?: DeepNodeTransformOptions
1346 ):
1347 | nodeOfKind<reducibleKindOf<this["kind"]>>
1348 | Extract<ReturnType<mapper>, null> {
1349 const ctx = this._tfContext(opts)
1350 if (!ctx.throughAliases) return this._tf(mapper, ctx) as never
1351 // an alias to a resolution still transforming resolves once the transform
1352 // returns, as do the checks a union it built left for then
1353 let transformed: BaseNode | null
1354 try {
1355 transformed = resolving(() => this._tf(mapper, ctx))
1356 } finally {
1357 for (const id in ctx.synth) $ark.nodesById.delete(ctx.synth[id].id)
1358 }
1359 if (!transformed || opts?.names) return transformed as never
1360 // again, now that synthetics have printed their names
1361 let name: string | undefined
1362 const names: Record<string, string> = {}
1363 // named as arktype names them, whatever a build names its callbacks
1364 const expression = withoutHoleNames(transformed.expression)
1365 for (const id in ctx.synth) {
1366 if (id === this.id) name = `synthetic${hashOf(expression)}`
1367 else
1368 names[id] = `synthetic${hashOf(`${expression}\n${ctx.synth[id].name}`)}`
1369 }
1370 const named =
1371 isEmptyObject(names) ? transformed : (
1372 this.transform(mapper, { ...opts, names })
1373 )
1374 if (!name) return named as never
1375 return printSelfAsThis(
1376 this.transform(mapper, {
1377 ...opts,
1378 names: { ...names, [this.id]: name }
1379 }) as never,
1380 named as BaseRoot
1381 ) as never
1382 }
1383
1384 /** the context a transform starts with */
1385 protected _tfContext(

Callers 3

createRootApplyFunction · 0.90
rewriteFileFunction · 0.50
rewriteJsonFunction · 0.50

Calls 7

resolvingFunction · 0.90
withoutHoleNamesFunction · 0.90
hashOfFunction · 0.90
isEmptyObjectFunction · 0.90
printSelfAsThisFunction · 0.90
_tfMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected