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.

70 lines 2.54 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. * * `data` and `metadata` belong here for the same reason, and their absence was * a live corruption rather than a latent one. Message `data`/`metadata` carry * caller-authored documents, and once Ratify proof bundles and signed * revocation lists travel in them the transform is not merely untidy: a * `RevocationList` whose `revoked_certs` arrives as `revokedCerts` cannot be * reconstructed byte-for-byte, so its signature no longer verifies and the * cross-deployment kill switch fails closed for the wrong reason. Anything * signed must survive a round trip unmodified. */ const VERBATIM_VALUE_KEYS = new Set([ 'headers', 'input', 'output', 'input_schema', 'inputSchema', 'output_schema', 'outputSchema', 'data', 'metadata', ]); 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