Skip to content
This repository was archived by the owner on Aug 18, 2018. It is now read-only.

Commit e6a326f

Browse files
committed
all with types
1 parent c24c46a commit e6a326f

15 files changed

Lines changed: 65 additions & 43 deletions

src/demo/books/books.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class BooksController {
3636
// TEST 1
3737
// this test merge data with cache (this not include author or photos)
3838
console.log('BooksRequest#1 received (author data from server)',
39-
(<IDataResource>this.books[2].relationships.author.data).attributes
39+
(<Jsonapi.IResource>this.books[2].relationships.author.data).attributes
4040
);
4141

4242
console.log('BooksRequest#2 requested');
4343
let books2 = this.BooksService.all(
4444
success => {
4545
console.log('BooksRequest#2 received (author data from cache)',
46-
(<IDataResource>books2[1].relationships.author.data)
46+
(<Jsonapi.IResource>books2[1].relationships.author.data)
4747
);
4848
}
4949
);
@@ -53,7 +53,7 @@ class BooksController {
5353
let book1 = this.BooksService.get(1,
5454
success => {
5555
console.log('BookRequest#3 received (author data from cache)',
56-
(<IDataResource>book1.relationships.author.data).attributes
56+
(<Jsonapi.IResource>book1.relationships.author.data).attributes
5757
);
5858
});
5959
},

src/library/interfaces/collection.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IResource } from './resource';
22
import { IPage } from './page';
3+
import { IDataResource } from './data-resource';
34

45
export interface ICollection extends Array<IResource> {
56
$length: number;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { IDataResource } from './data-resource';
2+
import { IDocument } from '../interfaces/document';
3+
14
interface IDataCollection extends IDocument {
25
data: IDataResource[];
36
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { IDocument } from './document';
2+
import { IDataResource } from './data-resource';
3+
14
interface IDataObject extends IDocument {
25
data: IDataResource;
36
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
interface IDataResource {
2-
type: string;
3-
id: string;
4-
attributes?: any;
5-
relationships?: any;
6-
links?: ILinks;
7-
meta?: any;
8-
}
1+
import { IAttributes } from '../interfaces';
2+
3+
interface IDataResource {
4+
type: string;
5+
id: string;
6+
attributes?: IAttributes;
7+
relationships?: any;
8+
links?: ILinks;
9+
meta?: any;
10+
}
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { IDataResource } from '../interfaces/data-resource';
2+
13
// http://org/format/#document-top-level
2-
interface IDocument {
3-
// data in child interface IJsonapiCollection
4-
// error in child interface IJsonapiErrors
5-
jsonapi?: string;
6-
links?: ILinks;
7-
included?: Array<IDataResource>;
8-
meta?: Object;
4+
interface IDocument {
5+
// data in child interface IJsonapiCollection
6+
// error in child interface IJsonapiErrors
7+
jsonapi?: string;
8+
links?: ILinks;
9+
included?: Array<IDataResource>;
10+
meta?: Object;
911

10-
promise?: any;
11-
}
12+
promise?: any;
13+
}

src/library/interfaces/errors.d.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
interface IErrors extends IDocument {
2-
errors: [
3-
{
4-
code?: string,
5-
source?: {
6-
attributes?: string,
7-
pointer: string
8-
},
9-
title?: string,
10-
detail?: string
11-
}
12-
];
13-
}
1+
import { IDocument } from './document';
2+
3+
interface IErrors extends IDocument {
4+
errors: [
5+
{
6+
code?: string,
7+
source?: {
8+
attributes?: string,
9+
pointer: string
10+
},
11+
title?: string,
12+
detail?: string
13+
}
14+
];
15+
}

src/library/interfaces/relationship.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ICollection, IResource } from '../interfaces';
2+
import { IDataResource } from './data-resource';
23

34
interface IRelationship {
45
// IDataResource added for this reason:

src/library/interfaces/resource.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { IRelationships, ICollection, IParamsResource, IService } from './index';
2+
import { IDataResource } from './data-resource';
3+
import { IDataObject } from './data-object';
24

35
export interface IResource extends IDataResource {
46
is_new: boolean;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { ISchema, IResource, ICollection, IParamsCollection, ICache, IParamsResource } from './index';
22

33
export interface IService {
4-
smartfilter?: string;
5-
schema?: ISchema;
4+
type: string;
5+
schema: ISchema;
66
getPrePath(): string;
77
getPath(): string;
8-
register? (): boolean;
8+
register(): boolean;
99
get<T extends IResource>(id: string | number, params?: IParamsResource | Function, fc_success?: Function, fc_error?: Function): T;
1010
all(params?: IParamsCollection | Function, success?: Function, error?: Function): ICollection;
1111
delete (id: String, params?: IParamsResource | Function, success?: Function, error?: Function): void;
12-
getService? (): any; // any, becouse depends of extended class
12+
getService<T extends IService> ():T;
1313
clearMemoryCache? (): boolean;
14-
new? (): IResource;
14+
new?<T extends IResource>(): T;
1515
memorycache: ICache;
1616
}

0 commit comments

Comments
 (0)