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
| 1 | import { checkedProps } from './checked-props' |
| 2 | import type { Fields } from './fields' |
| 3 | import { fieldsOf } from './fields-of' |
| 4 | import { isRecord } from './is-record' |
| 5 | import { refusal } from './refusal' |
| 6 | import { TOKEN } from './token' |
| 7 | |
| 8 | /** |
| 9 | * The row's fields from one entry, or a refusal naming the first thing |
| 10 | * wrong: the entry's shape, the event, then each property in turn. |
| 11 | * |
| 12 | * Nothing is sent from an entry refused here: the row reaches the ingest as |
| 13 | * written, so this check is the gate between the argument and the wire. |
| 14 | * |
| 15 | * @param entry the event's name and properties as the caller passed them |
| 16 | * @returns the entry's checked event name and properties, as `Fields` |
| 17 | */ |
| 18 | export function checkedFields(entry: unknown): Fields { |
| 19 | if (!isRecord(entry)) { |
| 20 | throw refusal('takes one entry, { event, props? }') |
| 21 | } |
| 22 | |
| 23 | const { event, props = {} } = entry |
| 24 | |
| 25 | if (typeof event !== 'string' || !TOKEN.test(event)) { |
| 26 | throw refusal('takes an event name, a snake_case token') |
| 27 | } |
| 28 | |
| 29 | return fieldsOf(event, checkedProps(props, 'log')) |
| 30 | } |