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

Function writeIntersectionCombinator

ark/type/standalone/combinators.ts:1221–1277  ·  view source on GitHub ↗
(
	js: CombinatorCompiler,
	node: IntersectionNode
)

Source from the content-addressed store, hash-verified

1219 node.tfs ? "transformingNarrowedAfter" : "narrowedAfter"
1220
1221const writeIntersectionCombinator = (
1222 js: CombinatorCompiler,
1223 node: IntersectionNode
1224): string => {
1225 const shape = js.shapes && writeShape(js, node)
1226 if (shape) return shape
1227 const predicates = node.inner.predicate?.map(predicate =>
1228 writePredicate(js, predicate)
1229 )
1230 const narrowed =
1231 predicates?.length === 1 ?
1232 predicates[0]
1233 : predicates && writeCall("narrowedByEach", `[${predicates.join(", ")}]`)
1234 const unnarrowed = narrowed && unnarrowedOf(node)
1235 if (unnarrowed) {
1236 reachRootsOf(js, unnarrowed)
1237 return writeCall(
1238 narrowedAfterOf(unnarrowed),
1239 readChecker(js, unnarrowed),
1240 narrowed
1241 )
1242 }
1243 const refinements = node.preStruct.map(child => writeCheck(js, child))
1244 const structure = node.structure && writeStructure(js, node.structure)
1245 const within =
1246 structure && narrowed ?
1247 writeCall(
1248 narrowedAfterOf(node.structure!),
1249 !node.structure!.tfs ? structure
1250 // one that transforms is asked whether it allows data before
1251 // its narrow reads it: with a ctx where a callback of its reads
1252 // one, which asked with none would be passed none
1253 : node.structure!.checksCtx ? writeCall("readingCtx", structure)
1254 : node.structure!.hasAlias ? writeCall("holdingAlias", structure)
1255 : structure,
1256 narrowed
1257 )
1258 : (structure ?? narrowed)
1259 // props check data is an object, as their basis would
1260 if (
1261 within &&
1262 !refinements.length &&
1263 (!node.basis ||
1264 ((node.structure?.props.length || node.structure?.index) &&
1265 isObjectCheck(node.basis)))
1266 )
1267 return within
1268 return writeCall(
1269 "intersection",
1270 node.basis ? writeCheck(js, node.basis) : "0",
1271 `[${refinements.join(", ")}]`,
1272 within,
1273 node.basis && node.brief !== checkOf(node.basis)!.description ?
1274 JSON.stringify(node.brief)
1275 : undefined
1276 )
1277}
1278

Callers 1

writeCheckerFunction · 0.85

Calls 12

writePredicateFunction · 0.85
writeCallFunction · 0.85
unnarrowedOfFunction · 0.85
reachRootsOfFunction · 0.85
narrowedAfterOfFunction · 0.85
readCheckerFunction · 0.85
writeCheckFunction · 0.85
writeStructureFunction · 0.85
isObjectCheckFunction · 0.85
checkOfFunction · 0.85
writeShapeFunction · 0.70
mapMethod · 0.65

Tested by

no test coverage detected