@opble/entity
v1.0.3
Published
Provide shared schemas for entities.
Readme
@opble/entity
Shared Zod schema primitives and timestamp utilities for domain entities across @opble packages.
Installation
npm install @opble/entityString schemas
| Export | Description |
|--------|-------------|
| TrimmedString() | z.string() that trims whitespace before validation |
| UpperTrimmedString() | TrimmedString() converted to uppercase |
| CurrencyString() | ISO 4217 3-letter currency code (e.g. USD) |
| DateString() | YYYY-MM-DD formatted date string |
import { TrimmedString, CurrencyString, DateString } from '@opble/entity';
const schema = z.object({
name: TrimmedString(),
currency: CurrencyString(),
dob: DateString(),
});Timestamp schemas
| Export | Type | Description |
|--------|------|-------------|
| TimestampSchema | number | Single Unix timestamp (seconds) with default now |
| TimestampsSchema | { createdAt: number, updatedAt: number } | Numeric created/updated timestamps |
| DateTimestampsSchema | { createdAt: Date, updatedAt: Date } | Created/updated as Date objects |
Type guards
import { isTimestamp, isTimestamps, isDateTimestamps } from '@opble/entity';
isTimestamp(value) // value is number
isTimestamps(value) // value has { createdAt: number, updatedAt: number }
isDateTimestamps(value) // value has { createdAt: Date, updatedAt: Date }License
UNLICENSED
