schemas

Defines Effect Schema conventions for API contracts with snake_case to camelCase bridging.

10|3|Updated Oct 23, 2023
One-click install
npx skills add https://github.com/Layer-Fi/layer-react --skill schemas-layer-fi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: schemas
Source: https://github.com/Layer-Fi/layer-react/tree/main/src/schemas
Command: npx skills add https://github.com/Layer-Fi/layer-react --skill schemas-layer-fi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect, @internationalized/date.

What problem does it solve? It keeps every API contract in a React/TypeScript app consistent by making Effect Schema the single source of truth for decoded types, wire types, fixture generators, and MSW encoders, eliminating hand-written parallel interfaces and drift between frontend and backend shapes. ## Core Features & Use Cases - Field naming bridge: Converts backend snake_case keys to camelCase app fields via Schema.fromKey, and derives mutation bodies from Encoded wire types. - Shared schema utilities: Provides UnwrappedDataResponseSchema, open/transformed enum helpers, pagination envelopes, calendar date schemas, and a non-recursive BigDecimal stand-in that avoids TS2589 inference blowups. - Recursive and union schemas: Documents the Schema.suspend plus paired-interface pattern for tree structures and per-file union arms for polymorphic payloads. - Use Case: When adding a new invoices endpoint, define one schema under features/invoices/, reuse PaginatedResponseSchema for list responses, and let hooks, fixtures, and MSW mocks all derive from that single definition. ## Quick Start Ask the assistant to create an Effect Schema for a new API response following the schemas conventions, providing the backend contract so field names and nullability are not guessed.

Frequently Asked Questions about schemas

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I map snake_case API fields to camelCase in Effect Schema?▼

Use Schema.propertySignature combined with Schema.fromKey inside Schema.Struct. The schema decodes the snake_case wire key into a camelCase property, so call sites never handle the raw naming convention.

How do I define a recursive schema in Effect Schema without errors?▼

Extract non-recursive fields into a shared const, declare paired Type and Encoded interfaces that self-reference via ReadonlyArray, and wrap the recursive arm in Schema.suspend with an explicit return type annotation.

Should I use Schema.NullOr or Schema.NullishOr for optional API fields?▼

Default to Schema.NullishOr because backends often omit a field on one endpoint and return explicit null on another. Reserve NullOr or UndefinedOr for contracts that genuinely distinguish the two states, such as PATCH bodies.

Why does BigDecimal cause TS2589 errors in React state?▼

BigDecimal's recursive type explodes TypeScript inference in React state and TanStack Form values. Use the NonRecursiveBigDecimal flat value/scale stand-in and convert to BigDecimal only at arithmetic boundaries.

How do I handle unknown enum values from the backend?▼

Use createOpenEnumSchema when the value is displayed as-is, or createTransformedEnumSchema with a default when logic branches on it. Bare Schema.Enums hard-fails on unrecognized members and can take down the whole view.

When should a plain TypeScript type be used instead of Effect Schema?▼

Use a plain type or interface for internal-only types with no wire format, which belong in src/types. Every payload that crosses an API boundary should be an Effect Schema so decoding, encoding, fixtures, and mocks derive from one definition.