Skip to content

Commit a7c531b

Browse files
committed
:fix: typings and JSONData declaration
1 parent 352217e commit a7c531b

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A parser for [JSON:API](https://jsonapi.org/) format that maps data to models us
1313
## Example usage
1414

1515
```typescript
16-
import { Attr, JSONAPI, Model, Rel } from "../src";
16+
import { Attr, JSONAPI, Model, Rel } from "@monade/json-api-parser";
1717

1818
export const DateParser = (data: any) => new Date(data);
1919

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { JSONModel } from "./JSONModel";
2-
export interface JSONData {
2+
export interface JSONDataWithMeta<Meta> {
33
data: JSONModel | JSONModel[];
44
included: JSONModel[];
5+
links?: {
6+
self: string;
7+
related?: string;
8+
};
9+
meta?: Meta;
10+
}
11+
export interface JSONData extends JSONDataWithMeta<any> {
512
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "A parser for JSON:API format that maps data to models using decorators, inspired by retrofit.",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.esm.js",
7+
"types": "dist/types/index.d.ts",
78
"repository": "https://github.com/monade/json-api-parser",
89
"author": "Monade",
910
"license": "MIT",

src/Parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class Parser {
4444
} else if ("data" in data && !("id" in data)) {
4545
return this.parse(data.data, data.included || included);
4646
} else {
47-
return this.parseElement(data, included) as T;
47+
return this.parseElement(data, included);
4848
}
4949
}
5050

src/interfaces/JSONData.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { JSONModel } from "./JSONModel";
22

3-
export interface JSONData {
3+
export interface JSONDataWithMeta<Meta> {
44
data: JSONModel | JSONModel[];
55
included: JSONModel[];
6+
links?: {
7+
self: string;
8+
related?: string;
9+
},
10+
meta?: Meta;
611
}
12+
13+
export interface JSONData extends JSONDataWithMeta<any> {}

0 commit comments

Comments
 (0)