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

Function addPrototypeKeyConstraint

ark/sets/fromJsonSchema.ts:1286–1309  ·  view source on GitHub ↗
(
	target: PrototypeKeyTarget,
	key: string,
	value: BaseRoot,
	isRequired: boolean
)

Source from the content-addressed store, hash-verified

1284}
1285
1286const addPrototypeKeyConstraint = (
1287 target: PrototypeKeyTarget,
1288 key: string,
1289 value: BaseRoot,
1290 isRequired: boolean
1291): void => {
1292 target.index.push({
1293 signature: {
1294 domain: "string",
1295 pattern: [{ rule: `^${escapeRegex(key)}$` }]
1296 },
1297 value
1298 })
1299 if (isRequired) {
1300 const pred = opaque(
1301 ["ownKey", key],
1302 `an object with its own ${key}`,
1303 (data: dict) => hasOwn(data, key),
1304 `\`Object.prototype\` key \`${key}\``
1305 )
1306 ownKeyPredicates.set(pred.predicate, key)
1307 target.predicate.push(pred)
1308 }
1309}
1310
1311const decimalParts = (n: number): [coeff: bigint, exp: number] => {
1312 const s = `${n}`

Callers 2

readObjectFunction · 0.85
constObjectRootFunction · 0.85

Calls 5

hasOwnFunction · 0.90
opaqueFunction · 0.85
escapeRegexFunction · 0.70
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected