dref
v1.0.0
specification.json

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
AttributeTypeAllowed valuesDescription
authorityenumclient, internal, externalOriginating source of truth: Client (user/consumer apps), Internal (microservices & business logic), or External (third-party systems). Defaults to internal when omitted.
ttlstring<integer><unit> — s (sec), m (min), h (hr), d (day), M (month), y (year); e.g. 5s, 2m, 24h, 30d, 1MRetention duration expression. An omitted ttl is lifecycle-manager-determined (persistent by default) and is not modelled in DRef; only explicit durations are expressed.
countrange-Inclusive instance-count range { min, max }. Either bound optional; min defaults to 0 when omitted; absent means unbounded count.
property.authorityenumclient, internal, externalPer-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
TypeExampleDescription
String"user@example.com"UTF-8 character string
Number19.99, -3.564-bit IEEE floating-point
Integer42, 100, -3Whole number with no fractional part
Booleantrue / falseBinary 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 Standard
regl.dev

DRef 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)