Skip to content
module@warp-drive/schema-dsl

Call Signature

ts
function Trait(target): void;

Defined in: entities/trait.ts:70

Class Decorator

Marks a class as a trait — a reusable collection of fields that can be composed onto a Resource (or another Trait) via trait.

The trait's name is derived from the class name (dasherized) unless a name string is passed explicitly. Its mode defaults to 'polaris'.

Each decorated property on the class contributes one entry to the compiled fields array, in declaration order. Unlike Resource, no $type or constructor DerivedField is ever added, since a trait's fields are merged into whichever resource composes it.

Parameters

target

AnyConstructor

Returns

void

Example

ts
import { Trait, field } from '@warp-drive/schema-dsl';

@Trait
export class Timestamped {
  @field({ type: 'date-time' }) declare createdAt: string;
  @field({ type: 'date-time' }) declare updatedAt: string;
}
json
{
  "name": "timestamped",
  "mode": "polaris",
  "fields": [
    { "kind": "field", "name": "createdAt", "type": "date-time" },
    { "kind": "field", "name": "updatedAt", "type": "date-time" }
  ]
}

Since

5.9.0

Call Signature

ts
function Trait(name, options?): (target) => void;

Defined in: entities/trait.ts:71

Class Decorator

Marks a class as a trait — a reusable collection of fields that can be composed onto a Resource (or another Trait) via trait.

The trait's name is derived from the class name (dasherized) unless a name string is passed explicitly. Its mode defaults to 'polaris'.

Each decorated property on the class contributes one entry to the compiled fields array, in declaration order. Unlike Resource, no $type or constructor DerivedField is ever added, since a trait's fields are merged into whichever resource composes it.

Parameters

name

string

options?

TraitOptions

Returns

(target) => void

Example

ts
import { Trait, field } from '@warp-drive/schema-dsl';

@Trait
export class Timestamped {
  @field({ type: 'date-time' }) declare createdAt: string;
  @field({ type: 'date-time' }) declare updatedAt: string;
}
json
{
  "name": "timestamped",
  "mode": "polaris",
  "fields": [
    { "kind": "field", "name": "createdAt", "type": "date-time" },
    { "kind": "field", "name": "updatedAt", "type": "date-time" }
  ]
}

Since

5.9.0

Call Signature

ts
function Trait(options): (target) => void;

Defined in: entities/trait.ts:72

Class Decorator

Marks a class as a trait — a reusable collection of fields that can be composed onto a Resource (or another Trait) via trait.

The trait's name is derived from the class name (dasherized) unless a name string is passed explicitly. Its mode defaults to 'polaris'.

Each decorated property on the class contributes one entry to the compiled fields array, in declaration order. Unlike Resource, no $type or constructor DerivedField is ever added, since a trait's fields are merged into whichever resource composes it.

Parameters

options

TraitOptions

Returns

(target) => void

Example

ts
import { Trait, field } from '@warp-drive/schema-dsl';

@Trait
export class Timestamped {
  @field({ type: 'date-time' }) declare createdAt: string;
  @field({ type: 'date-time' }) declare updatedAt: string;
}
json
{
  "name": "timestamped",
  "mode": "polaris",
  "fields": [
    { "kind": "field", "name": "createdAt", "type": "date-time" },
    { "kind": "field", "name": "updatedAt", "type": "date-time" }
  ]
}

Since

5.9.0

Released under the MIT License.