effect-schema
Use when @effect/schema patterns including schema definition, validation, parsing, encoding, and transformations. Use for type-safe data validation in Effect applications.
What this skill does
# Effect Schema
Master type-safe data validation and transformation with @effect/schema. This
skill covers schema definition, parsing, encoding, and advanced schema patterns
for building robust data pipelines.
## Basic Schema Types
### Primitive Schemas
```typescript
import { Schema } from "@effect/schema"
// Primitive types
const StringSchema = Schema.String
const NumberSchema = Schema.Number
const BooleanSchema = Schema.Boolean
const BigIntSchema = Schema.BigInt
const SymbolSchema = Schema.Symbol
// Special types
const UndefinedSchema = Schema.Undefined
const VoidSchema = Schema.Void
const NullSchema = Schema.Null
const UnknownSchema = Schema.Unknown
const AnySchema = Schema.Any
```
### Literal Values
```typescript
import { Schema } from "@effect/schema"
// String literal
const HelloSchema = Schema.Literal("hello")
// Number literal
const FortyTwoSchema = Schema.Literal(42)
// Boolean literal
const TrueSchema = Schema.Literal(true)
// Multiple literals (union)
const StatusSchema = Schema.Literal("pending", "approved", "rejected")
```
## Struct Schemas
### Basic Struct
```typescript
import { Schema } from "@effect/schema"
// Define user schema
const UserSchema = Schema.Struct({
id: Schema.String,
name: Schema.String,
age: Schema.Number,
email: Schema.String
})
// Infer TypeScript type
type User = Schema.Schema.Type<typeof UserSchema>
// { id: string; name: string; age: number; email: string }
```
### Optional Fields
```typescript
import { Schema } from "@effect/schema"
const PersonSchema = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optional(Schema.String),
phone: Schema.optional(Schema.String)
})
type Person = Schema.Schema.Type<typeof PersonSchema>
// { name: string; age: number; email?: string; phone?: string }
```
### Nested Schemas
```typescript
import { Schema } from "@effect/schema"
const AddressSchema = Schema.Struct({
street: Schema.String,
city: Schema.String,
zipCode: Schema.String
})
const UserWithAddressSchema = Schema.Struct({
id: Schema.String,
name: Schema.String,
address: AddressSchema
})
```
## Arrays and Collections
### Array Schemas
```typescript
import { Schema } from "@effect/schema"
// Array of strings
const StringArraySchema = Schema.Array(Schema.String)
// Array of numbers
const NumberArraySchema = Schema.Array(Schema.Number)
// Array of complex objects
const UsersSchema = Schema.Array(UserSchema)
// Non-empty array
const NonEmptyStringArray = Schema.NonEmptyArray(Schema.String)
```
### Tuple Schemas
```typescript
import { Schema } from "@effect/schema"
// Fixed tuple
const CoordinatesSchema = Schema.Tuple(
Schema.Number, // latitude
Schema.Number // longitude
)
// Tuple with optional elements
const ResponseSchema = Schema.Tuple(
Schema.Number, // status code
Schema.String, // message
Schema.optional(Schema.Unknown) // optional data
)
```
### Record Schemas
```typescript
import { Schema } from "@effect/schema"
// String keys, number values
const ScoresSchema = Schema.Record({
key: Schema.String,
value: Schema.Number
})
// Using template literals for keys
const ConfigSchema = Schema.Record({
key: Schema.TemplateLiteral("config.", Schema.String),
value: Schema.String
})
```
## Union and Intersection
### Union Types
```typescript
import { Schema } from "@effect/schema"
// Simple union
const StringOrNumberSchema = Schema.Union(
Schema.String,
Schema.Number
)
// Tagged union (discriminated)
const ShapeSchema = Schema.Union(
Schema.Struct({
kind: Schema.Literal("circle"),
radius: Schema.Number
}),
Schema.Struct({
kind: Schema.Literal("rectangle"),
width: Schema.Number,
height: Schema.Number
})
)
type Shape = Schema.Schema.Type<typeof ShapeSchema>
// { kind: "circle"; radius: number } | { kind: "rectangle"; width: number; height: number }
```
### Intersection Types
```typescript
import { Schema } from "@effect/schema"
const TimestampsSchema = Schema.Struct({
createdAt: Schema.Date,
updatedAt: Schema.Date
})
const UserWithTimestampsSchema = Schema.extend(
UserSchema,
TimestampsSchema
)
// Equivalent to intersection
const ManualIntersection = Schema.Struct({
...UserSchema.fields,
...TimestampsSchema.fields
})
```
## Parsing and Validation
### Synchronous Parsing
```typescript
import { Schema } from "@effect/schema"
const UserSchema = Schema.Struct({
name: Schema.String,
age: Schema.Number
})
// Parse unknown data
const parseUser = Schema.decodeUnknownSync(UserSchema)
try {
const user = parseUser({ name: "Alice", age: 30 })
console.log(user) // { name: "Alice", age: 30 }
} catch (error) {
console.error("Validation failed:", error)
}
// Invalid data throws
parseUser({ name: "Bob" }) // Throws: missing 'age' field
```
### Effect-Based Parsing
```typescript
import { Schema } from "@effect/schema"
import { Effect } from "effect"
const parseUserEffect = Schema.decodeUnknown(UserSchema)
const program = Effect.gen(function* () {
const user = yield* parseUserEffect({ name: "Alice", age: 30 })
return user
})
// Handle parse errors
const safeProgram = program.pipe(
Effect.catchTag("ParseError", (error) =>
Effect.sync(() => {
console.error("Parse error:", error.message)
return null
})
)
)
```
### Encoding
```typescript
import { Schema } from "@effect/schema"
// Encode typed data back to raw format
const encodeUser = Schema.encodeSync(UserSchema)
const user: User = { name: "Alice", age: 30 }
const encoded = encodeUser(user)
// { name: "Alice", age: 30 }
```
## Schema Transformations
### Transform Schemas
```typescript
import { Schema } from "@effect/schema"
// String to Date transformation
const DateFromString = Schema.transform(
Schema.String,
Schema.Date,
{
decode: (s) => new Date(s),
encode: (d) => d.toISOString()
}
)
// Parse ISO string to Date
const parseDate = Schema.decodeUnknownSync(DateFromString)
const date = parseDate("2024-01-01T00:00:00Z")
// Date object
// Encode Date back to string
const encodeDate = Schema.encodeSync(DateFromString)
const isoString = encodeDate(new Date())
// "2024-01-01T00:00:00.000Z"
```
### Validated Transformations
```typescript
import { Schema } from "@effect/schema"
import { ParseResult } from "@effect/schema/ParseResult"
// Email validation and transformation
const EmailSchema = Schema.transformOrFail(
Schema.String,
Schema.String,
{
decode: (s) => {
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s)) {
return ParseResult.fail(
ParseResult.type(Schema.String.ast, s, "Invalid email format")
)
}
return ParseResult.succeed(s.toLowerCase())
},
encode: (s) => ParseResult.succeed(s)
}
)
```
## Refinements and Constraints
### String Refinements
```typescript
import { Schema } from "@effect/schema"
// Min/max length
const UsernameSchema = Schema.String.pipe(
Schema.minLength(3),
Schema.maxLength(20)
)
// Pattern matching
const UUIDSchema = Schema.String.pipe(
Schema.pattern(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)
)
// Email
const EmailSchema = Schema.String.pipe(Schema.pattern(/^[^\s@]+@[^\s@]+\.[^\s@]+$/))
// Starts with
const HttpUrlSchema = Schema.String.pipe(Schema.startsWith("http"))
```
### Number Refinements
```typescript
import { Schema } from "@effect/schema"
// Positive numbers
const PositiveSchema = Schema.Number.pipe(Schema.positive())
// Range
const AgeSchema = Schema.Number.pipe(
Schema.greaterThanOrEqualTo(0),
Schema.lessThanOrEqualTo(120)
)
// Integer
const IntegerSchema = Schema.Number.pipe(Schema.int())
// Multiple of
const EvenSchema = Schema.Number.pipe(Schema.multipleOf(2))
```
### Custom Refinements
```typescript
import { Schema } from "@effect/schema"
const PasswordSchema = Schema.String.pipe(
Schema.minLength(8),
Schema.filter((s) => ({
message: () => "Password must contain uppercase, lowercaRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.