Options
All
  • Public
  • Public/Protected
  • All
Menu

JSONAPI-typescript

Build Status Version

TypeScript type information for compile-time validation of JSON:API documents. Supports TS 2.3 and above.

How to use this

  1. Install this package

    npm install --save-dev jsonapi-typescript
  2. Import this module

    import * as JSONAPI from 'jsonapi-typescript';
  3. check to see if json types are validated correctly

import * as JSONAPI from 'jsonapi-typescript';

// ✅ This should be OK
let doc: JSONAPI.Document = {
  data: {
    type: 'articles',
    id: '1'
  }
};

// ⛔️ This should NOT be OK ("result" is not a valid JSON:API top-level key)
let doc: JSONAPI.Document = {
  result: "Success!"
};

// ⛔️ This should NOT be OK ( empty Array is not a valid JSON:API document )
let doc: JSONAPI.Document = [];

© 2017 Mike North, All Rights Reserved.

Index

Type aliases

AttributesObject

AttributesObject: object

Type declaration

CollectionResourceDoc

CollectionResourceDoc: DocWithData<Array<ResourceObject<T, A>>>

Document

Error

Error: object

Type declaration

Errors

Errors: ErrorObject[]

Included

Included: ResourceObject[]

Link

Link: string | object

MetaObject

MetaObject: Object

A JSON object MUST be at the root of every JSON API request and responsecontaining data. This object defines a document’s “top level”. A document MUST contain at least one of the following top-level members:

PrimaryData

PrimaryData: ResourceObject<T, A> | Array<ResourceObject<T, A>>

RelationshipObject

ResourceLinkage

ResourceLinkage: null | never[] | ResourceIdentifierObject | ResourceIdentifierObject[]

SingleResourceDoc

SingleResourceDoc: DocWithData<ResourceObject<T, A>>

Variables

Let cachedRecords

cachedRecords: any

Functions

Const createService

  • createService(host: string, onRes: any, onErr: any): AxiosInstance
  • Parameters

    • host: string
    • onRes: any
    • onErr: any

    Returns AxiosInstance

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc