Specification & Quickstarts
A model is a name, five governance attributes, and a list of properties. This is the entire mental model.
Model-level governance attributes
4 attributes| Attribute | Type | Allowed values | Description |
|---|---|---|---|
| authority | enum | client, internal, external | Originating source of truth: Client (user/consumer apps), Internal (microservices & business logic), or External (third-party systems). Defaults to internal when omitted. |
| ttl | string | <integer><unit> — s (sec), m (min), h (hr), d (day), M (month), y (year); e.g. 5s, 2m, 24h, 30d, 1M | Retention duration expression. An omitted ttl is lifecycle-manager-determined (persistent by default) and is not modelled in DRef; only explicit durations are expressed. |
| count | range | - | Inclusive instance-count range { min, max }. Either bound optional; min defaults to 0 when omitted; absent means unbounded count. |
| property.authority | enum | client, internal, external | Per-property authority: the principal permitted to set this field's value. Omitted properties inherit the model-level authority (which defaults to internal). Enforced at runtime by validateWrite(data, model, writer). |
Field types
9 types| Type | Example | Description |
|---|---|---|
| String | "user@example.com" | UTF-8 character string |
| Number | 19.99, -3.5 | 64-bit IEEE floating-point |
| Integer | 42, 100, -3 | Whole number with no fractional part |
| Boolean | true / false | Binary flag |
| Date | "2026-09-08" | Calendar date (YYYY-MM-DD) |
| DateTime | "2026-09-08T10:00:00Z" | ISO-8601 UTC timestamp |
| Time | "14:30:00" | Wall-clock time (HH:mm:ss) |
| List | ["String"], ["#LineItem"] | Ordered array of elements (list: true) |
| Reference | "#Customer" | Foreign link to another model |
Field validation & rules (Regl)
Regl StandardDRef does not maintain a separate rule catalog. It normatively adopts the canonical 40-rule catalog from the Regl Specification (regl.dev). Primitive rules targeting strings, numbers, integers, booleans, collections, and dates/times are defined, typed, localized, and tested by Regl.
String rules (minLength, maxLength, pattern, email, uuid...)Number & Integer rules (greaterThan, lessThan, positive...)Temporal rules (dateFormat, isoDate, isoDateTime, epoch...)List rules (range, unique)Boolean rules (isTrue, isFalse)Universal rules (enum, notNull)
import { validateInstance } from '@dref/validator';
const customerModel = {
name: 'Customer',
authority: 'client',
properties: [
{
name: 'email',
type: 'String',
required: true,
rules: [
{ type: 'email' },
{ type: 'lowercase' },
{ type: 'trimmed' }
]
},
{
name: 'age',
type: 'Number',
required: false,
rules: [
{ type: 'positiveInteger' },
{ type: 'greaterThanOrEqual', param: 18 }
]
}
]
};
const { isValid, errors } = validateInstance(
{ email: 'User@Example.com', age: 24 },
customerModel
);
// isValid === false (email must be lowercase)