@yavin/model-types
TypeScript icon, indicating that this package has built-in type declarations

0.2.0-beta.891 • Public • Published

@yavin/model-types

Contains the TypeScript definitions for the following json:api objects stored in the webservice package

Dashboard, DashboardWidget, Report, DeliveryRule, User, Role

Examples

You'll need to cast your responses using the JSONAPI<RequestedObject, IncludedType> type with the models you are requesting

import type { Dashboard, DashboardWidget, JSONAPI } from '@yavin/model-types';

const response = await fetch('yavin.webservice/api/v1/dashboards/12?include=widgets');

const jsonApi = (await response.json()) as JSONAPI<Dashboard, DashboardWidget>;

//now typed
jsonApi.data.attributes.presentation.layout[0].widgetId;
jsonApi.included[0].type === 'dashboardWidgets';
jsonApi.included[0].attributes.requests[0];

Here are more examples of fetching resources and how to type the response

fetch('*') Response Type
/reports JSONAPI<Report[]>
/report/12 JSONAPI<Report>
/report/12?include=owner JSONAPI<Report, User>
/dashboards/13?include=widgets JSONAPI<Dashboard, DashboardWidget>
/deliveryRules/3?include=deliveredItem JSONAPI<DeliveryRule, Report | Dashboard>

Readme

Keywords

Package Sidebar

Install

npm i @yavin/model-types

Weekly Downloads

3

Version

0.2.0-beta.891

License

MIT

Unpacked Size

9.86 kB

Total Files

13

Last publish

Collaborators

  • kevinhinterlong
  • navi-release