|
14 | 14 | */
|
15 | 15 |
|
16 | 16 | declare module 'json-api' {
|
17 |
| -declare type JsonApiResourceId<Type: string> = { |
18 |
| -id: string, |
19 |
| -type: Type |
| 17 | +declare type JSON = |
| 18 | +| null |
| 19 | +| void |
| 20 | +| string |
| 21 | +| number |
| 22 | +| boolean |
| 23 | +| { [string]: JSON } |
| 24 | +| Array<JSON>; |
| 25 | + |
| 26 | +declare type JSONAPIMeta = { [string]: JSON }; |
| 27 | + |
| 28 | +declare type JSONAPILink = |
| 29 | +| string |
| 30 | +| {| |
| 31 | +href: string, |
| 32 | +meta?: JSONAPIMeta, |
| 33 | +|}; |
| 34 | + |
| 35 | +declare type JSONAPILinks = { |
| 36 | +self?: JSONAPILink, |
| 37 | +related?: JSONAPILink, |
| 38 | +[string]: JSONAPILink, |
20 | 39 | };
|
21 | 40 |
|
22 |
| -declare type JsonApiResource<Type, Attributes = Object> = { |
23 |
| -...JsonApiResourceId<Type>, |
24 |
| -attributes?: Attributes, |
25 |
| -relationships?: Object, |
26 |
| -links?: Object, |
27 |
| -meta?: Object |
| 41 | +declare type JSONAPIPaginationLinks = { |
| 42 | +first?: ?JSONAPILink, |
| 43 | +last?: ?JSONAPILink, |
| 44 | +prev?: ?JSONAPILink, |
| 45 | +next?: ?JSONAPILink, |
28 | 46 | };
|
29 | 47 |
|
30 |
| -declare type JsonApiDocument<PrimaryResourceTypes> = { |
31 |
| -data: PrimaryResourceTypes | Array<PrimaryResourceTypes> | null, |
| 48 | +declare type JSONAPIError = {| |
| 49 | +id?: string, |
| 50 | +links?: {| |
| 51 | +about: JSONAPILink, |
| 52 | +|}, |
| 53 | +status?: string, |
| 54 | +code?: string, |
| 55 | +title?: string, |
| 56 | +detail?: string, |
| 57 | +source?: { |
| 58 | +pointer?: string, |
| 59 | +parameter?: string, |
| 60 | +}, |
| 61 | +meta?: JSONAPIMeta, |
| 62 | +|}; |
| 63 | + |
| 64 | +declare type JSONAPIObject = {| |
| 65 | +version?: string, |
| 66 | +meta?: JSONAPIMeta, |
| 67 | +|}; |
| 68 | + |
| 69 | +declare type JSONAPIAttributes = { |
| 70 | +[string]: JSON, |
32 | 71 | };
|
| 72 | + |
| 73 | +declare type JSONAPIResourceIdentifier = {| |
| 74 | +id: string, |
| 75 | +type: string, |
| 76 | +meta?: JSONAPIMeta, |
| 77 | +|}; |
| 78 | + |
| 79 | +declare type JSONAPIResourceLinkage = |
| 80 | +| Array<JSONAPIResourceIdentifier> |
| 81 | +| JSONAPIResourceIdentifier |
| 82 | +| null; |
| 83 | + |
| 84 | +declare type JSONAPIRelationship = {| |
| 85 | +links?: { |
| 86 | +self?: JSONAPILink, |
| 87 | +related?: JSONAPILink, |
| 88 | +} & JSONAPILinks, |
| 89 | +data?: JSONAPIResourceLinkage, |
| 90 | +meta?: JSONAPIMeta, |
| 91 | +|}; |
| 92 | + |
| 93 | +declare type JSONAPIRelationships = { |
| 94 | +[string]: JSONAPIRelationship, |
| 95 | +}; |
| 96 | + |
| 97 | +declare type JSONAPIResource = {| |
| 98 | +id?: string, |
| 99 | +type: string, |
| 100 | +attributes?: JSONAPIAttributes, |
| 101 | +relationships?: JSONAPIRelationships, |
| 102 | +links?: JSONAPILinks, |
| 103 | +meta?: JSONAPIMeta, |
| 104 | +|}; |
| 105 | + |
| 106 | +declare type JSONAPIDataDocument = {| |
| 107 | +data: |
| 108 | +| Array<JSONAPIResource | JSONAPIResourceIdentifier> |
| 109 | +| JSONAPIResource |
| 110 | +| JSONAPIResourceIdentifier |
| 111 | +| null, |
| 112 | +meta?: JSONAPIMeta, |
| 113 | +jsonapi?: JSONAPIObject, |
| 114 | +links?: JSONAPIPaginationLinks & JSONAPILinks, |
| 115 | +included?: Array<JSONAPIResource>, |
| 116 | +|}; |
| 117 | + |
| 118 | +declare type JSONAPIMetaDocument = {| |
| 119 | +meta: JSONAPIMeta, |
| 120 | +jsonapi?: JSONAPIObject, |
| 121 | +links?: JSONAPILinks, |
| 122 | +|}; |
| 123 | + |
| 124 | +declare type JSONAPIErrorDocument = {| |
| 125 | +errors: Array<JSONAPIError>, |
| 126 | +meta?: JSONAPIMeta, |
| 127 | +jsonapi?: JSONAPIObject, |
| 128 | +links?: JSONAPILinks, |
| 129 | +|}; |
| 130 | + |
| 131 | +declare type JSONAPIDocument = |
| 132 | +| JSONAPIDataDocument |
| 133 | +| JSONAPIMetaDocument |
| 134 | +| JSONAPIErrorDocument; |
33 | 135 | }
|
0 commit comments