MCPcopy Index your code
hub / github.com/simstudioai/sim / parseFunctionArgs

Function parseFunctionArgs

apps/sim/tools/convex/utils.ts:43–65  ·  view source on GitHub ↗
(
  args: Record<string, unknown> | string | undefined
)

Source from the content-addressed store, hash-verified

41 * Convex function endpoints require a named-argument object.
42 */
43export function parseFunctionArgs(
44 args: Record<string, unknown> | string | undefined
45): Record<string, unknown> {
46 if (args === undefined || args === null) return {}
47 if (typeof args === 'string') {
48 const trimmed = args.trim()
49 if (!trimmed) return {}
50 let parsed: unknown
51 try {
52 parsed = JSON.parse(trimmed)
53 } catch {
54 throw new Error('Invalid function arguments: expected a JSON object like {"key": "value"}')
55 }
56 if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
57 throw new Error('Invalid function arguments: expected a JSON object, not an array or scalar')
58 }
59 return parsed as Record<string, unknown>
60 }
61 if (typeof args !== 'object' || Array.isArray(args)) {
62 throw new Error('Invalid function arguments: expected a JSON object, not an array or scalar')
63 }
64 return args
65}
66
67/**
68 * Parses a Convex API response body, surfacing non-OK HTTP statuses (e.g. 401

Callers 4

mutation.tsFile · 0.90
run_function.tsFile · 0.90
query.tsFile · 0.90
action.tsFile · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected