json-api-models

A lightweight layer for working with JSON:API data.

MIT License

Stars
22

Bot releases are hidden (Show)

json-api-models - Release 0.2.0-beta.1 Latest Release

Published by tobyzerner 5 months ago

⚠️ Breaking Changes

  • Rewrite TypeScript support to allow Intellisense based on JSON:API resource schema. For example:

    type UsersSchema = {
        type: 'users';
        id: string;
        attributes: {
            name: string;
        };
        relationships: {
            dog: { data?: { type: 'dogs'; id: string } | null };
        };
    };
    
    class User extends Model<UsersSchema> {}
    

    To type related resources, you can provide a collection of all models as the second generic.

    type DogsSchema = {
        // ...
    };
    
    type Schemas = {
        users: User;
        dogs: Dog;
    };
    
    class User extends Model<UsersSchema, Schemas> {}
    class Dog extends Model<DogsSchema, Schemas> {}
    
  • The Store now returns proxied Model instances to implement field getters, instead of Model depending on Store and defining getters for present fields.

  • Remove the Query helper. Use URLSearchParams instead.

  • Remove Model attribute casting functionality. Define getters instead:

    class User extends Model<UserSchema> {
        get createdAtDate() {
            return new Date(this.createdAt);
        }
    }
    
  • Remove the Model.getAttribute() and Model.getRelationship() methods.

  • Remove CJS and IIFE exports. Package is now only exported as an ES module.

json-api-models - Release 0.1.0-beta.8

Published by tobyzerner over 2 years ago

Added

  • Support model type inference:
const store = new Store({ users: User });
store.find('users', '1') // User

Removed

  • Remove the Store.model method. Models must now be defined when the Store is constructed.
json-api-models - Release 0.1.0-beta.7

Published by tobyzerner about 3 years ago

Fixed

  • Fix regression with attribute casting not handling dates correctly, and add more sophisticated handling of primitives, constructables, and callables.
json-api-models - Release 0.1.0-beta.6

Published by tobyzerner about 3 years ago

Fixed

  • Fix attribute cast type definition and invoke as function rather than with new.
json-api-models - Release 0.1.0-beta.5

Published by tobyzerner about 3 years ago

Added

  • Query: add append, set, and delete methods.
  • Export useful JSON:API types: JsonApiDocument, JsonApiIdentifier, JsonApiResource, JsonApiRelationships, and JsonApiRelationship.

Removed

  • Query: remove push method.
json-api-models - Release 0.1.0-beta.4

Published by tobyzerner over 3 years ago

Fixed

  • Fix casts not working correctly.
json-api-models - Release 0.1.0-beta.3

Published by tobyzerner over 3 years ago

Added

  • Added ability to define typecasts for attributes on custom models.

Changed

  • Change compilation target to es2017 for Object.entries support.
json-api-models -

Published by tobyzerner over 3 years ago