From fca64b09079c0febf585bfec930dc78cfb2eb821 Mon Sep 17 00:00:00 2001 From: Marco Spengler Date: Fri, 8 Jan 2021 12:05:47 +0100 Subject: [PATCH 1/4] Change meta key in LinkObject to be optional as specified in JSON:API --- packages/ts-json-api/src/types/shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ts-json-api/src/types/shared.ts b/packages/ts-json-api/src/types/shared.ts index 5151329..1366c9e 100644 --- a/packages/ts-json-api/src/types/shared.ts +++ b/packages/ts-json-api/src/types/shared.ts @@ -10,7 +10,7 @@ export interface Links { */ export interface LinkObject { href: string; - meta: Meta; + meta?: Meta; } /** From 0eac08eb3fa943073cc1493adf2504f9bc2eb740 Mon Sep 17 00:00:00 2001 From: Marco Spengler Date: Fri, 8 Jan 2021 12:07:37 +0100 Subject: [PATCH 2/4] Provide interface for pagination links as described in JSON:API --- packages/ts-json-api/src/types/shared.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/ts-json-api/src/types/shared.ts b/packages/ts-json-api/src/types/shared.ts index 1366c9e..581d78c 100644 --- a/packages/ts-json-api/src/types/shared.ts +++ b/packages/ts-json-api/src/types/shared.ts @@ -5,6 +5,13 @@ export interface Links { [index: string]: string | LinkObject; } +export interface PaginationLinks { + first?: string | LinkObject | null; + last?: string | LinkObject | null; + prev?: string | LinkObject | null; + next?: string | LinkObject | null; +} + /** * A Link. */ From 69fd56fd9095a93872a2aa4eebfcf4a033f597f3 Mon Sep 17 00:00:00 2001 From: Marco Spengler Date: Fri, 8 Jan 2021 12:12:53 +0100 Subject: [PATCH 3/4] Update changelog --- packages/ts-json-api/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/ts-json-api/CHANGELOG.md b/packages/ts-json-api/CHANGELOG.md index b18061c..fb6b863 100644 --- a/packages/ts-json-api/CHANGELOG.md +++ b/packages/ts-json-api/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.1] - 2021-01-08 +### Added +- `publication links` interface as part of the JSON:API 1.0 specification + +### Changed +- `meta` key in `link` object to be optional to be JSON:API 1.0 compliant + ## [1.0.0] - 2020-02-17 ### Changed - Moved to [TSDX](https://https://github.com/palmerhq/tsdx) for development. From 739e687337b4a3b8bbd766bdd3feeb241f751cec Mon Sep 17 00:00:00 2001 From: Marco Spengler Date: Wed, 13 Jan 2021 07:30:45 +0100 Subject: [PATCH 4/4] Add usage for pagination links in top level resources --- packages/ts-json-api/src/types/requests.ts | 4 ++-- packages/ts-json-api/src/types/responses.ts | 10 ++++----- packages/ts-json-api/src/types/shared.ts | 23 ++++++++++++++++----- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/packages/ts-json-api/src/types/requests.ts b/packages/ts-json-api/src/types/requests.ts index 9eb0b35..8c397a6 100644 --- a/packages/ts-json-api/src/types/requests.ts +++ b/packages/ts-json-api/src/types/requests.ts @@ -1,5 +1,5 @@ import { NewResourceObject, ResourceObject } from './resourceObjects'; -import { Links, Meta } from './shared'; +import { Meta, TopLevelLinks } from './shared'; /** * A Request to be sent to a JSON API-compliant server. @@ -11,7 +11,7 @@ export interface Request< > { data: D; included?: ResourceObject[]; - links?: Links; + links?: TopLevelLinks; errors?: [Error]; meta?: Meta; } diff --git a/packages/ts-json-api/src/types/responses.ts b/packages/ts-json-api/src/types/responses.ts index 2743283..808a343 100644 --- a/packages/ts-json-api/src/types/responses.ts +++ b/packages/ts-json-api/src/types/responses.ts @@ -1,5 +1,5 @@ import { ResourceObject, ResourceObjectOrObjects } from './resourceObjects'; -import { Links, Meta } from './shared'; +import { Links, Meta, TopLevelLinks } from './shared'; /** * A Response for sure containing data. @@ -9,7 +9,7 @@ export interface ResponseWithData< > { data: D; included?: ResourceObject[]; - links?: Links; + links?: TopLevelLinks; errors?: Error[]; meta?: Meta; } @@ -22,7 +22,7 @@ export interface ResponseWithErrors< > { data?: D; included?: ResourceObject[]; - links?: Links; + links?: TopLevelLinks; errors: Error[]; meta?: Meta; } @@ -35,7 +35,7 @@ export interface ResponseWithMetaData< > { data?: D; included?: ResourceObject[]; - links?: Links; + links?: TopLevelLinks; errors?: Error[]; meta: Meta; } @@ -48,7 +48,7 @@ export interface Response< > { data?: D; included?: ResourceObject[]; - links?: Links; + links?: TopLevelLinks; errors?: Error[]; meta?: Meta; } diff --git a/packages/ts-json-api/src/types/shared.ts b/packages/ts-json-api/src/types/shared.ts index 581d78c..29915ea 100644 --- a/packages/ts-json-api/src/types/shared.ts +++ b/packages/ts-json-api/src/types/shared.ts @@ -1,17 +1,30 @@ +/** + * A single Link. + */ +export type Link = string | LinkObject; + /** * An index of Links. */ export interface Links { - [index: string]: string | LinkObject; + [index: string]: Link; } +/** + * Top level pagination Links. + */ export interface PaginationLinks { - first?: string | LinkObject | null; - last?: string | LinkObject | null; - prev?: string | LinkObject | null; - next?: string | LinkObject | null; + first?: Link | null; + last?: Link | null; + prev?: Link | null; + next?: Link | null; } +/** + * The top level Links. + */ +export type TopLevelLinks = Links & PaginationLinks; + /** * A Link. */