SDK
Primitive ReferenceLast updated on
Last updated on
Build and validate primitive data types
Primitives are validated data types used throughout Paradoc. Object primitives accept plain objects and provide builders. Scalar primitives (date, datetime, time, percentage, and rating) accept one value and do not have builders. Every primitive provides parse() and safeParse() for validation.
Available Primitives
| Primitive | Description |
|---|---|
| attachment | File attachment |
| metadata | Artifact metadata |
| signature | Signature value |
| address | Postal address |
| bbox | Bounding box |
| coordinate | Lat/lng point |
| date | Date (YYYY-MM-DD) |
| datetime | Date and time |
| duration | ISO 8601 duration |
| identification | ID document |
| money | Monetary amount with currency |
| organization | Organization info |
| percentage | Percentage value |
| person | Person name |
| phone | Phone number (E.164) |
| rating | Rating value |
| time | Time only |
Usage Patterns
Object Pattern
Pass a plain object for immediate validation:
import { money } from '@paradoc/core'
// Validates and returns the Money object
const price = money({ amount: 99.99, currency: 'USD' })
// Throws if invalid
const invalid = money({ amount: 'not a number', currency: 'USD' })Builder Pattern
Chain methods to construct incrementally:
import { money } from '@paradoc/core'
const price = money()
.amount(99.99)
.currency('USD')
.build()Static Methods
Parse unknown data from external sources:
import { money } from '@paradoc/core'
// Throws on error
const price = money.parse(jsonData)
// Returns result object
const result = money.safeParse(jsonData)
if (result.success) {
console.log(result.data.amount)
} else {
console.error(result.error)
}Using with Forms
Primitives are commonly used when filling form data:
import { p, money, address } from '@paradoc/core'
const form = p.form({
name: 'invoice',
fields: {
total: { type: 'money', label: 'Total Amount' },
billingAddress: { type: 'address', label: 'Billing Address' }
}
})
const filled = form.fill({
fields: {
total: money({ amount: 150.00, currency: 'USD' }),
billingAddress: address()
.line1('123 Main Street')
.locality('New York')
.region('NY')
.postalCode('10001')
.country('US')
.build()
}
})Related
- Form Fields - Field types that use primitives
- Primitive Schemas - JSON Schema definitions