spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / telemetry / hooks / entries / checked-props / checked-props.ts
41 lines · 1.2 KBRaw
1import { checkedValue } from '../checked-value'
2import { isRecord } from '../is-record'
3import type { Method } from '../method'
4import { PROP_LIMIT } from '../prop-limit'
5import { refusal } from '../refusal'
6import { TOKEN } from '../token'
7
8/**
9 * An entry's properties as they go into the row, or a refusal naming the
10 * first thing wrong: the shape, the count, then each key and value in turn.
11 *
12 * @param props what the caller passed as `props`
13 * @param method the method the properties were passed to, named in a refusal
14 * @returns the properties by key, each value checked
15 */
16export function checkedProps(
17 props: unknown,
18 method: Method,
19): Record<string, string | number | boolean> {
20 if (!isRecord(props)) {
21 throw refusal('props: an object of properties by key', method)
22 }
23
24 const entries = Object.entries(props)
25
26 if (entries.length > PROP_LIMIT) {
27 throw refusal(`props: at most ${PROP_LIMIT} properties`, method)
28 }
29
30 const checked: Record<string, string | number | boolean> = {}
31
32 for (const [key, value] of entries) {
33 if (!TOKEN.test(key)) {
34 throw refusal('props: every key is a snake_case token', method)
35 }
36
37 checked[key] = checkedValue(key, value, method)
38 }
39
40 return checked
41}