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

Method jsEntry

ark/schema/structure/structure.ts:1623–1661  ·  view source on GitHub ↗

writes the check of one of data's entries

(
		js: NodeCompiler,
		keyDomain: "string" | "symbol"
	)

Source from the content-addressed store, hash-verified

1621
1622 /** writes the check of one of data's entries */
1623 protected jsEntry(
1624 js: NodeCompiler,
1625 keyDomain: "string" | "symbol"
1626 ): NodeCompiler {
1627 if (this.index) {
1628 for (const node of this.index) {
1629 js.if(js.allows(node.signature, "k"), () =>
1630 js.travKey(
1631 keyDomain === "string" ? jsArrayPathKey(js) : "k",
1632 "data[k]",
1633 node.value
1634 )
1635 )
1636 }
1637 }
1638
1639 if (this.undeclared === "reject" && keyDomain === "string") {
1640 // for...in also reaches inherited keys, which aren't undeclared
1641 const isOwn = "Object.prototype.hasOwnProperty.call(data, k)"
1642 const skipsInherited =
1643 !this.index && !this.sequence && js.trav === "Allows"
1644 if (skipsInherited) js.line(`if (!${isOwn}) continue`)
1645 const props = this.props.filter(prop => typeof prop.key === keyDomain)
1646 if (props.length) compileDeclaredKeySwitch(js, props)
1647 const reject = () =>
1648 js.trav === "Allows" ?
1649 js.return(false)
1650 : js.if(js.undeclaredFails?.(this) ?? js.error(this, "k"), () =>
1651 js.return(false)
1652 )
1653 const declaresKey = this._jsDeclaresKey(js)
1654 const conditions = declaresKey === "false" ? [] : [`!(${declaresKey})`]
1655 if (!this.index && !skipsInherited) conditions.push(isOwn)
1656 if (conditions.length) js.if(conditions.join(" && "), reject)
1657 else reject()
1658 }
1659
1660 return js
1661 }
1662}
1663
1664// a structure's props of the other kind as this one, all of them or those at

Callers 1

compileMethod · 0.95

Calls 8

_jsDeclaresKeyMethod · 0.95
jsArrayPathKeyFunction · 0.85
compileDeclaredKeySwitchFunction · 0.85
ifMethod · 0.80
allowsMethod · 0.80
lineMethod · 0.80
filterMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected