Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

request-body.ts

21 lines596 Bytes

1function isRecord(value: unknown): value is Record<string, unknown> {
2 return typeof value === 'object' && value !== null
3}
4​
5/**
6 * Extract the payload record from an `api.otel-*` route's POST body,
7 * unwrapping the `forwardedProps` envelope the test harness may nest it in.
8 * Throws on any non-object shape.
9 */
10export function recordFromBody(body: unknown): Record<string, unknown> {
11 if (!isRecord(body)) {
12 throw new Error('Invalid request body')
13 }
14​
15 const data = body.forwardedProps ?? body
16 if (!isRecord(data)) {
17 throw new Error('Invalid request body')
18 }
19​
20 return data