infinum / datx

DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.
https://datx.dev
MIT License
140 stars 7 forks source link

[Proposal] - introduce new @Field decorator for jsonapi package instead of @Attribute #1164

Closed isBatak closed 1 year ago

isBatak commented 1 year ago

Relevant version

Relevant libraries

Breaking change

No

Description

Based on JSON:API standard attributes and relationships are both called fields. https://jsonapi.org/format/#document-resource-object-fields image

This change will better align library with JSON:API mindset.

import { Model } from '@datx/core';
import { Field, jsonapiModel } from '@datx/jsonapi';

class Pet extends jsonapiModel(Model) {
  static type = 'pet';

  @Field()
  public name: string;

  @Field({ defaultValue: 0 })
  public age: number;

  @Field({ toOne: Person })
  public owner: Person;
}