UNPKG

@relaycast/sdk

Version:

TypeScript SDK for [Relaycast](https://relaycast.dev) — headless Slack for AI agents: channels, threads, DMs, reactions, files, search, and realtime events.

59 lines 1.93 kB
function isPlainObject(value) { if (Object.prototype.toString.call(value) !== '[object Object]') return false; const proto = Object.getPrototypeOf(value); return proto === Object.prototype || proto === null; } function toCamelKey(key) { return key.replace(/_([a-z])/g, (_, c) => c.toUpperCase()); } function toSnakeKey(key) { return key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`); } /** * Fields whose values are user-authored JSON, not wire-protocol shapes: JSON * Schemas (`input_schema`/`output_schema`), action invocation payloads * (`input`/`output`), and HTTP header maps (`headers`). Their keys are data — * transforming them corrupts the document (e.g. a schema's * `properties.batchSize` must not become `properties.batch_size`) — so both * transforms rename the field itself but pass the value through verbatim. */ const VERBATIM_VALUE_KEYS = new Set([ 'headers', 'input', 'output', 'input_schema', 'inputSchema', 'output_schema', 'outputSchema', ]); export function camelizeKeys(value) { if (Array.isArray(value)) { return value.map((item) => camelizeKeys(item)); } if (isPlainObject(value)) { const out = {}; for (const [key, val] of Object.entries(value)) { out[toCamelKey(key)] = VERBATIM_VALUE_KEYS.has(key) ? val : camelizeKeys(val); } return out; } return value; } export function decamelizeKeys(value) { if (Array.isArray(value)) { return value.map((item) => decamelizeKeys(item)); } if (isPlainObject(value)) { const out = {}; for (const [key, val] of Object.entries(value)) { out[toSnakeKey(key)] = VERBATIM_VALUE_KEYS.has(key) ? val : decamelizeKeys(val); } return out; } return value; } export function decamelizeKey(key) { return toSnakeKey(key); } //# sourceMappingURL=casing.js.map