@mx-space/api-client 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adaptors/axios.ts +34 -32
- package/adaptors/umi-request.ts +25 -22
- package/build/index.cjs.js +12 -32
- package/build/index.cjs.js.map +1 -1
- package/build/index.cjs.min.js +1 -1
- package/build/index.cjs.min.js.map +1 -1
- package/build/index.esm.js +13 -32
- package/build/index.esm.js.map +1 -1
- package/build/index.esm.min.js +1 -1
- package/build/index.esm.min.js.map +1 -1
- package/build/index.umd.js +12 -32
- package/build/index.umd.js.map +1 -1
- package/build/index.umd.min.js +1 -1
- package/build/index.umd.min.js.map +1 -1
- package/controllers/aggregate.ts +9 -5
- package/controllers/base.ts +3 -3
- package/controllers/category.ts +18 -7
- package/controllers/comment.ts +10 -6
- package/controllers/link.ts +11 -4
- package/controllers/note.ts +11 -7
- package/controllers/page.ts +10 -5
- package/controllers/post.ts +15 -8
- package/controllers/project.ts +10 -3
- package/controllers/recently.ts +10 -5
- package/controllers/say.ts +10 -5
- package/controllers/search.ts +14 -7
- package/controllers/snippet.ts +9 -4
- package/controllers/user.ts +10 -5
- package/core/attach-request.ts +1 -1
- package/core/client.ts +37 -47
- package/coverage/clover.xml +281 -274
- package/coverage/coverage-final.json +20 -20
- package/coverage/lcov-report/adaptors/axios.ts.html +48 -42
- package/coverage/lcov-report/adaptors/index.html +24 -24
- package/coverage/lcov-report/adaptors/umi-request.ts.html +42 -33
- package/coverage/lcov-report/auto-bind.ts.html +229 -0
- package/coverage/lcov-report/controllers/aggregate.ts.html +20 -8
- package/coverage/lcov-report/controllers/base.ts.html +4 -4
- package/coverage/lcov-report/controllers/category.ts.html +43 -10
- package/coverage/lcov-report/controllers/comment.ts.html +21 -9
- package/coverage/lcov-report/controllers/index.html +1 -1
- package/coverage/lcov-report/controllers/index.ts.html +2 -2
- package/coverage/lcov-report/controllers/link.ts.html +28 -7
- package/coverage/lcov-report/controllers/note.ts.html +21 -9
- package/coverage/lcov-report/controllers/page.ts.html +22 -7
- package/coverage/lcov-report/controllers/post.ts.html +37 -16
- package/coverage/lcov-report/controllers/project.ts.html +27 -6
- package/coverage/lcov-report/controllers/recently.ts.html +23 -8
- package/coverage/lcov-report/controllers/say.ts.html +23 -8
- package/coverage/lcov-report/controllers/search.ts.html +31 -10
- package/coverage/lcov-report/controllers/snippet.ts.html +22 -7
- package/coverage/lcov-report/controllers/user.ts.html +23 -8
- package/coverage/lcov-report/core/attach-request.ts.html +13 -13
- package/coverage/lcov-report/core/client.ts.html +120 -150
- package/coverage/lcov-report/core/error.ts.html +1 -1
- package/coverage/lcov-report/core/index.html +18 -18
- package/coverage/lcov-report/core/index.ts.html +1 -1
- package/coverage/lcov-report/index.html +26 -26
- package/coverage/lcov-report/index.ts.html +244 -0
- package/coverage/lcov-report/models/aggregate.ts.html +1 -1
- package/coverage/lcov-report/models/category.ts.html +1 -1
- package/coverage/lcov-report/models/index.html +1 -1
- package/coverage/lcov-report/utils/auto-bind.ts.html +18 -18
- package/coverage/lcov-report/utils/index.html +1 -1
- package/coverage/lcov-report/utils/index.ts.html +3 -3
- package/coverage/lcov.info +496 -485
- package/esm/adaptors/axios.d.ts +2 -2
- package/esm/adaptors/axios.js +1 -0
- package/esm/adaptors/axios.js.map +1 -1
- package/esm/adaptors/umi-request.d.ts +2 -2
- package/esm/adaptors/umi-request.js +1 -0
- package/esm/adaptors/umi-request.js.map +1 -1
- package/esm/controllers/aggregate.d.ts +25 -8
- package/esm/controllers/aggregate.js.map +1 -1
- package/esm/controllers/base.d.ts +17 -5
- package/esm/controllers/category.d.ts +64 -13
- package/esm/controllers/category.js.map +1 -1
- package/esm/controllers/comment.d.ts +42 -10
- package/esm/controllers/comment.js.map +1 -1
- package/esm/controllers/link.d.ts +5 -4
- package/esm/controllers/link.js.map +1 -1
- package/esm/controllers/note.d.ts +42 -12
- package/esm/controllers/note.js.map +1 -1
- package/esm/controllers/page.d.ts +22 -8
- package/esm/controllers/page.js.map +1 -1
- package/esm/controllers/post.d.ts +24 -11
- package/esm/controllers/post.js.map +1 -1
- package/esm/controllers/project.d.ts +4 -3
- package/esm/controllers/project.js.map +1 -1
- package/esm/controllers/recently.d.ts +30 -8
- package/esm/controllers/recently.js.map +1 -1
- package/esm/controllers/say.d.ts +15 -5
- package/esm/controllers/say.js.map +1 -1
- package/esm/controllers/search.d.ts +168 -9
- package/esm/controllers/search.js.map +1 -1
- package/esm/controllers/snippet.d.ts +16 -6
- package/esm/controllers/snippet.js.map +1 -1
- package/esm/controllers/user.d.ts +28 -8
- package/esm/controllers/user.js.map +1 -1
- package/esm/core/attach-request.d.ts +1 -1
- package/esm/core/attach-request.js.map +1 -1
- package/esm/core/client.d.ts +9 -6
- package/esm/core/client.js +13 -32
- package/esm/core/client.js.map +1 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interfaces/adapter.d.ts +9 -8
- package/esm/interfaces/client.d.ts +1 -1
- package/esm/interfaces/request.d.ts +22 -13
- package/esm/interfaces/types.d.ts +2 -0
- package/esm/interfaces/types.js +2 -0
- package/esm/interfaces/types.js.map +1 -0
- package/index.ts +2 -1
- package/interfaces/adapter.ts +29 -24
- package/interfaces/client.ts +1 -1
- package/interfaces/request.ts +45 -20
- package/{types/helper.d.ts → interfaces/types.ts} +0 -0
- package/lib/adaptors/axios.d.ts +2 -2
- package/lib/adaptors/axios.js +1 -0
- package/lib/adaptors/axios.js.map +1 -1
- package/lib/adaptors/umi-request.d.ts +2 -2
- package/lib/adaptors/umi-request.js +1 -0
- package/lib/adaptors/umi-request.js.map +1 -1
- package/lib/controllers/aggregate.d.ts +25 -8
- package/lib/controllers/aggregate.js.map +1 -1
- package/lib/controllers/base.d.ts +17 -5
- package/lib/controllers/category.d.ts +64 -13
- package/lib/controllers/category.js.map +1 -1
- package/lib/controllers/comment.d.ts +42 -10
- package/lib/controllers/comment.js.map +1 -1
- package/lib/controllers/link.d.ts +5 -4
- package/lib/controllers/link.js.map +1 -1
- package/lib/controllers/note.d.ts +42 -12
- package/lib/controllers/note.js.map +1 -1
- package/lib/controllers/page.d.ts +22 -8
- package/lib/controllers/page.js.map +1 -1
- package/lib/controllers/post.d.ts +24 -11
- package/lib/controllers/post.js.map +1 -1
- package/lib/controllers/project.d.ts +4 -3
- package/lib/controllers/project.js.map +1 -1
- package/lib/controllers/recently.d.ts +30 -8
- package/lib/controllers/recently.js.map +1 -1
- package/lib/controllers/say.d.ts +15 -5
- package/lib/controllers/say.js.map +1 -1
- package/lib/controllers/search.d.ts +168 -9
- package/lib/controllers/search.js.map +1 -1
- package/lib/controllers/snippet.d.ts +16 -6
- package/lib/controllers/snippet.js.map +1 -1
- package/lib/controllers/user.d.ts +28 -8
- package/lib/controllers/user.js.map +1 -1
- package/lib/core/attach-request.d.ts +1 -1
- package/lib/core/attach-request.js.map +1 -1
- package/lib/core/client.d.ts +9 -6
- package/lib/core/client.js +13 -33
- package/lib/core/client.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/interfaces/adapter.d.ts +9 -8
- package/lib/interfaces/client.d.ts +1 -1
- package/lib/interfaces/request.d.ts +22 -13
- package/lib/interfaces/types.d.ts +2 -0
- package/lib/interfaces/types.js +3 -0
- package/lib/interfaces/types.js.map +1 -0
- package/package.json +5 -5
- package/tsconfig.json +25 -4
- package/tsconfig.types.json +18 -0
- package/types/adaptors/axios.d.ts +3 -0
- package/types/adaptors/umi-request.d.ts +3 -0
- package/types/controllers/aggregate.d.ts +64 -0
- package/types/controllers/base.d.ts +39 -0
- package/types/controllers/category.d.ts +114 -0
- package/types/controllers/comment.d.ts +81 -0
- package/types/controllers/index.d.ts +16 -0
- package/types/controllers/link.d.ts +16 -0
- package/types/controllers/note.d.ts +94 -0
- package/types/controllers/page.d.ts +59 -0
- package/types/controllers/post.d.ts +72 -0
- package/types/controllers/project.d.ts +15 -0
- package/types/controllers/recently.d.ts +61 -0
- package/types/controllers/say.d.ts +37 -0
- package/types/controllers/search.d.ts +247 -0
- package/types/controllers/snippet.d.ts +33 -0
- package/types/controllers/user.d.ts +54 -0
- package/types/core/attach-request.d.ts +2 -0
- package/types/core/client.d.ts +29 -0
- package/types/core/error.d.ts +6 -0
- package/types/core/index.d.ts +2 -0
- package/types/dtos/comment.d.ts +6 -0
- package/types/index.d.ts +7 -0
- package/types/interfaces/adapter.d.ts +14 -0
- package/types/interfaces/client.d.ts +5 -0
- package/types/interfaces/controller.d.ts +4 -0
- package/types/interfaces/instance.d.ts +7 -0
- package/types/interfaces/options.d.ts +1 -0
- package/types/interfaces/params.d.ts +4 -0
- package/types/interfaces/request.d.ts +43 -0
- package/types/interfaces/types.d.ts +2 -0
- package/types/models/aggregate.d.ts +53 -0
- package/types/models/base.d.ts +37 -0
- package/types/models/category.d.ts +22 -0
- package/types/models/comment.d.ts +34 -0
- package/types/models/index.d.ts +14 -0
- package/types/models/link.d.ts +20 -0
- package/types/models/note.d.ts +30 -0
- package/types/models/page.d.ts +14 -0
- package/types/models/post.d.ts +15 -0
- package/types/models/project.d.ts +11 -0
- package/types/models/recently.d.ts +6 -0
- package/types/models/say.d.ts +6 -0
- package/types/models/setting.d.ts +66 -0
- package/types/models/snippet.d.ts +16 -0
- package/types/models/user.d.ts +21 -0
- package/types/utils/auto-bind.d.ts +4 -0
- package/types/utils/index.d.ts +5 -0
package/lib/controllers/say.d.ts
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
|
+
import { IRequestAdapter } from '../interfaces/adapter';
|
|
1
2
|
import { IController } from '../interfaces/controller';
|
|
3
|
+
import { IRequestHandler } from '../interfaces/request';
|
|
2
4
|
import { SayModel } from '../models/say';
|
|
3
5
|
import { HTTPClient } from '../core';
|
|
4
6
|
import { BaseCrudController } from './base';
|
|
5
7
|
declare module '../core/client' {
|
|
6
|
-
interface HTTPClient {
|
|
7
|
-
say: SayController
|
|
8
|
+
interface HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
9
|
+
say: SayController<ResponseWrapper>;
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
|
-
export declare class SayController extends BaseCrudController<SayModel> implements IController {
|
|
12
|
+
export declare class SayController<ResponseWrapper> extends BaseCrudController<SayModel, ResponseWrapper> implements IController {
|
|
11
13
|
protected client: HTTPClient;
|
|
12
14
|
base: string;
|
|
13
15
|
name: string;
|
|
14
16
|
constructor(client: HTTPClient);
|
|
15
|
-
get proxy():
|
|
17
|
+
get proxy(): IRequestHandler<ResponseWrapper>;
|
|
16
18
|
/**
|
|
17
19
|
* 获取随机一条
|
|
18
20
|
*/
|
|
19
21
|
getRandom(): import("../interfaces/request").RequestProxyResult<{
|
|
20
22
|
data: SayModel | null;
|
|
21
|
-
}, {
|
|
23
|
+
}, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
22
24
|
[key: string]: any;
|
|
23
25
|
data: {
|
|
24
26
|
data: SayModel | null;
|
|
25
27
|
};
|
|
28
|
+
} : ResponseWrapper extends {
|
|
29
|
+
data: {
|
|
30
|
+
data: SayModel | null;
|
|
31
|
+
};
|
|
32
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
33
|
+
data: {
|
|
34
|
+
data: SayModel | null;
|
|
35
|
+
};
|
|
26
36
|
}>;
|
|
27
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"say.js","sourceRoot":"","sources":["../../controllers/say.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"say.js","sourceRoot":"","sources":["../../controllers/say.ts"],"names":[],"mappings":";;;AAIA,iDAA4C;AAE5C,iCAA2C;AAW3C,MAAa,aACX,SAAQ,yBAA6C;IAMrD,YAAsB,MAAkB;QACtC,KAAK,CAAC,MAAM,CAAC,CAAA;QADO,WAAM,GAAN,MAAM,CAAY;QAHxC,SAAI,GAAG,MAAM,CAAA;QACb,SAAI,GAAG,KAAK,CAAA;QAIV,IAAA,oBAAQ,EAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAA6B,CAAA;IAC3D,CAAC;CACF;AAtBD,sCAsBC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRequestAdapter } from '../interfaces/adapter';
|
|
1
2
|
import { IController } from '../interfaces/controller';
|
|
2
3
|
import { IRequestHandler, RequestProxyResult } from '../interfaces/request';
|
|
3
4
|
import { PaginateResult } from '../models/base';
|
|
@@ -6,8 +7,8 @@ import { PostModel } from '../models/post';
|
|
|
6
7
|
import { PageModel } from '..';
|
|
7
8
|
import { HTTPClient } from '../core';
|
|
8
9
|
declare module '../core/client' {
|
|
9
|
-
interface HTTPClient {
|
|
10
|
-
search: SearchController
|
|
10
|
+
interface HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
11
|
+
search: SearchController<ResponseWrapper>;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
export declare type SearchType = 'post' | 'note';
|
|
@@ -16,14 +17,14 @@ export declare type SearchOption = {
|
|
|
16
17
|
order?: number;
|
|
17
18
|
rawAlgolia?: boolean;
|
|
18
19
|
};
|
|
19
|
-
export declare class SearchController implements IController {
|
|
20
|
+
export declare class SearchController<ResponseWrapper> implements IController {
|
|
20
21
|
private readonly client;
|
|
21
22
|
base: string;
|
|
22
23
|
name: string;
|
|
23
24
|
constructor(client: HTTPClient);
|
|
24
|
-
get proxy(): IRequestHandler
|
|
25
|
-
search(type: 'note', keyword: string, options?: Omit<SearchOption, 'rawAlgolia'>): Promise<RequestProxyResult<PaginateResult<Pick<NoteModel, 'modified' | 'id' | 'title' | 'created' | 'nid'
|
|
26
|
-
search(type: 'post', keyword: string, options?: Omit<SearchOption, 'rawAlgolia'>): Promise<RequestProxyResult<PaginateResult<Pick<PostModel, 'modified' | 'id' | 'title' | 'created' | 'slug' | 'category'
|
|
25
|
+
get proxy(): IRequestHandler<ResponseWrapper>;
|
|
26
|
+
search(type: 'note', keyword: string, options?: Omit<SearchOption, 'rawAlgolia'>): Promise<RequestProxyResult<PaginateResult<Pick<NoteModel, 'modified' | 'id' | 'title' | 'created' | 'nid'>>, ResponseWrapper>>;
|
|
27
|
+
search(type: 'post', keyword: string, options?: Omit<SearchOption, 'rawAlgolia'>): Promise<RequestProxyResult<PaginateResult<Pick<PostModel, 'modified' | 'id' | 'title' | 'created' | 'slug' | 'category'>>, ResponseWrapper>>;
|
|
27
28
|
/**
|
|
28
29
|
* 从 algolya 搜索
|
|
29
30
|
* https://www.algolia.com/doc/api-reference/api-methods/search/
|
|
@@ -42,7 +43,7 @@ export declare class SearchController implements IController {
|
|
|
42
43
|
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
43
44
|
*/
|
|
44
45
|
raw?: any;
|
|
45
|
-
}, {
|
|
46
|
+
}, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
46
47
|
[key: string]: any;
|
|
47
48
|
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
48
49
|
type: 'post';
|
|
@@ -56,7 +57,33 @@ export declare class SearchController implements IController {
|
|
|
56
57
|
*/
|
|
57
58
|
raw?: any;
|
|
58
59
|
};
|
|
59
|
-
}
|
|
60
|
+
} : ResponseWrapper extends {
|
|
61
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
62
|
+
type: 'post';
|
|
63
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
64
|
+
type: 'note';
|
|
65
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
66
|
+
type: 'page';
|
|
67
|
+
})> & {
|
|
68
|
+
/**
|
|
69
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
70
|
+
*/
|
|
71
|
+
raw?: any;
|
|
72
|
+
};
|
|
73
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
74
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
75
|
+
type: 'post';
|
|
76
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
77
|
+
type: 'note';
|
|
78
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
79
|
+
type: 'page';
|
|
80
|
+
})> & {
|
|
81
|
+
/**
|
|
82
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
83
|
+
*/
|
|
84
|
+
raw?: any;
|
|
85
|
+
};
|
|
86
|
+
}>, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
60
87
|
[key: string]: any;
|
|
61
88
|
data: RequestProxyResult<PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
62
89
|
type: 'post';
|
|
@@ -69,7 +96,60 @@ export declare class SearchController implements IController {
|
|
|
69
96
|
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
70
97
|
*/
|
|
71
98
|
raw?: any;
|
|
72
|
-
}, {
|
|
99
|
+
}, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
100
|
+
[key: string]: any;
|
|
101
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
102
|
+
type: 'post';
|
|
103
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
104
|
+
type: 'note';
|
|
105
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
106
|
+
type: 'page';
|
|
107
|
+
})> & {
|
|
108
|
+
/**
|
|
109
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
110
|
+
*/
|
|
111
|
+
raw?: any;
|
|
112
|
+
};
|
|
113
|
+
} : ResponseWrapper extends {
|
|
114
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
115
|
+
type: 'post';
|
|
116
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
117
|
+
type: 'note';
|
|
118
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
119
|
+
type: 'page';
|
|
120
|
+
})> & {
|
|
121
|
+
/**
|
|
122
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
123
|
+
*/
|
|
124
|
+
raw?: any;
|
|
125
|
+
};
|
|
126
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
127
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
128
|
+
type: 'post';
|
|
129
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
130
|
+
type: 'note';
|
|
131
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
132
|
+
type: 'page';
|
|
133
|
+
})> & {
|
|
134
|
+
/**
|
|
135
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
136
|
+
*/
|
|
137
|
+
raw?: any;
|
|
138
|
+
};
|
|
139
|
+
}>;
|
|
140
|
+
} : ResponseWrapper extends {
|
|
141
|
+
data: RequestProxyResult<PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
142
|
+
type: 'post';
|
|
143
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
144
|
+
type: 'note';
|
|
145
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
146
|
+
type: 'page';
|
|
147
|
+
})> & {
|
|
148
|
+
/**
|
|
149
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
150
|
+
*/
|
|
151
|
+
raw?: any;
|
|
152
|
+
}, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
73
153
|
[key: string]: any;
|
|
74
154
|
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
75
155
|
type: 'post';
|
|
@@ -83,6 +163,85 @@ export declare class SearchController implements IController {
|
|
|
83
163
|
*/
|
|
84
164
|
raw?: any;
|
|
85
165
|
};
|
|
166
|
+
} : ResponseWrapper extends {
|
|
167
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
168
|
+
type: 'post';
|
|
169
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
170
|
+
type: 'note';
|
|
171
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
172
|
+
type: 'page';
|
|
173
|
+
})> & {
|
|
174
|
+
/**
|
|
175
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
176
|
+
*/
|
|
177
|
+
raw?: any;
|
|
178
|
+
};
|
|
179
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
180
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
181
|
+
type: 'post';
|
|
182
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
183
|
+
type: 'note';
|
|
184
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
185
|
+
type: 'page';
|
|
186
|
+
})> & {
|
|
187
|
+
/**
|
|
188
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
189
|
+
*/
|
|
190
|
+
raw?: any;
|
|
191
|
+
};
|
|
192
|
+
}>;
|
|
193
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
194
|
+
data: RequestProxyResult<PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
195
|
+
type: 'post';
|
|
196
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
197
|
+
type: 'note';
|
|
198
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
199
|
+
type: 'page';
|
|
200
|
+
})> & {
|
|
201
|
+
/**
|
|
202
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
203
|
+
*/
|
|
204
|
+
raw?: any;
|
|
205
|
+
}, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
206
|
+
[key: string]: any;
|
|
207
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
208
|
+
type: 'post';
|
|
209
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
210
|
+
type: 'note';
|
|
211
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
212
|
+
type: 'page';
|
|
213
|
+
})> & {
|
|
214
|
+
/**
|
|
215
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
216
|
+
*/
|
|
217
|
+
raw?: any;
|
|
218
|
+
};
|
|
219
|
+
} : ResponseWrapper extends {
|
|
220
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
221
|
+
type: 'post';
|
|
222
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
223
|
+
type: 'note';
|
|
224
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
225
|
+
type: 'page';
|
|
226
|
+
})> & {
|
|
227
|
+
/**
|
|
228
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
229
|
+
*/
|
|
230
|
+
raw?: any;
|
|
231
|
+
};
|
|
232
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
233
|
+
data: PaginateResult<(Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category"> & {
|
|
234
|
+
type: 'post';
|
|
235
|
+
}) | (Pick<NoteModel, "id" | "title" | "modified" | "created" | "nid"> & {
|
|
236
|
+
type: 'note';
|
|
237
|
+
}) | (Pick<PageModel, "id" | "title" | "slug" | "modified" | "created"> & {
|
|
238
|
+
type: 'page';
|
|
239
|
+
})> & {
|
|
240
|
+
/**
|
|
241
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
242
|
+
*/
|
|
243
|
+
raw?: any;
|
|
244
|
+
};
|
|
86
245
|
}>;
|
|
87
246
|
}>;
|
|
88
247
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../controllers/search.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../controllers/search.ts"],"names":[],"mappings":";;;AAMA,iDAA4C;AAoB5C,MAAa,gBAAgB;IAI3B,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAH/C,SAAI,GAAG,QAAQ,CAAA;QACf,SAAI,GAAG,QAAQ,CAAA;QAGb,IAAA,oBAAQ,EAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IA6BD,MAAM,CACJ,IAAgB,EAChB,OAAe,EACf,UAA4C,EAAE;QAE9C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;YAC1B,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;SAChC,CAAC,CAAA;IACJ,CAAC;IACD;;;;;;OAMG;IACH,eAAe,CAAC,OAAe,EAAE,OAAsB;QACrD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CAuB9B,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC,CAAA;IACxC,CAAC;CACF;AAjFD,4CAiFC"}
|
|
@@ -1,23 +1,33 @@
|
|
|
1
|
+
import { IRequestAdapter } from '../interfaces/adapter';
|
|
1
2
|
import { IController } from '../interfaces/controller';
|
|
3
|
+
import { IRequestHandler } from '../interfaces/request';
|
|
2
4
|
import { SnippetModel } from '../models/snippet';
|
|
3
5
|
import { HTTPClient } from '../core';
|
|
4
6
|
declare module '../core/client' {
|
|
5
|
-
interface HTTPClient {
|
|
6
|
-
snippet: SnippetController
|
|
7
|
+
interface HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
8
|
+
snippet: SnippetController<ResponseWrapper>;
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
|
-
export declare class SnippetController implements IController {
|
|
11
|
+
export declare class SnippetController<ResponseWrapper> implements IController {
|
|
10
12
|
protected client: HTTPClient;
|
|
11
13
|
base: string;
|
|
12
14
|
name: string;
|
|
13
15
|
constructor(client: HTTPClient);
|
|
14
|
-
get proxy():
|
|
15
|
-
getById<T = unknown>(id: string): import("../interfaces/request").RequestProxyResult<SnippetModel<T>, {
|
|
16
|
+
get proxy(): IRequestHandler<ResponseWrapper>;
|
|
17
|
+
getById<T = unknown>(id: string): import("../interfaces/request").RequestProxyResult<SnippetModel<T>, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
16
18
|
[key: string]: any;
|
|
17
19
|
data: SnippetModel<T>;
|
|
20
|
+
} : ResponseWrapper extends {
|
|
21
|
+
data: SnippetModel<T>;
|
|
22
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
23
|
+
data: SnippetModel<T>;
|
|
18
24
|
}>;
|
|
19
|
-
getByReferenceAndName<T = unknown>(reference: string, name: string): import("../interfaces/request").RequestProxyResult<T, {
|
|
25
|
+
getByReferenceAndName<T = unknown>(reference: string, name: string): import("../interfaces/request").RequestProxyResult<T, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
20
26
|
[key: string]: any;
|
|
21
27
|
data: T;
|
|
28
|
+
} : ResponseWrapper extends {
|
|
29
|
+
data: T;
|
|
30
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
31
|
+
data: T;
|
|
22
32
|
}>;
|
|
23
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet.js","sourceRoot":"","sources":["../../controllers/snippet.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"snippet.js","sourceRoot":"","sources":["../../controllers/snippet.ts"],"names":[],"mappings":";;;AAIA,iDAA4C;AAY5C,MAAa,iBAAiB;IAI5B,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAHxC,SAAI,GAAG,UAAU,CAAA;QACjB,SAAI,GAAG,SAAS,CAAA;QAGd,IAAA,oBAAQ,EAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,OAAO,CAAc,EAAU;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,EAAmB,CAAA;IAC9C,CAAC;IAED,qBAAqB,CAAc,SAAiB,EAAE,IAAY;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAK,CAAA;IAC7C,CAAC;CACF;AAnBD,8CAmBC"}
|
|
@@ -1,34 +1,54 @@
|
|
|
1
|
+
import { IRequestAdapter } from '../interfaces/adapter';
|
|
1
2
|
import { IController } from '../interfaces/controller';
|
|
3
|
+
import { IRequestHandler } from '../interfaces/request';
|
|
2
4
|
import { TLogin, UserModel } from '../models/user';
|
|
3
5
|
import { HTTPClient } from '../core';
|
|
4
6
|
declare module '../core/client' {
|
|
5
|
-
interface HTTPClient {
|
|
6
|
-
user: UserController
|
|
7
|
-
master: UserController
|
|
7
|
+
interface HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
8
|
+
user: UserController<ResponseWrapper>;
|
|
9
|
+
master: UserController<ResponseWrapper>;
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
|
-
export declare class UserController implements IController {
|
|
12
|
+
export declare class UserController<ResponseWrapper> implements IController {
|
|
11
13
|
private readonly client;
|
|
12
14
|
constructor(client: HTTPClient);
|
|
13
15
|
base: string;
|
|
14
16
|
name: string[];
|
|
15
|
-
get proxy():
|
|
16
|
-
getMasterInfo(): import("../interfaces/request").RequestProxyResult<UserModel, {
|
|
17
|
+
get proxy(): IRequestHandler<ResponseWrapper>;
|
|
18
|
+
getMasterInfo(): import("../interfaces/request").RequestProxyResult<UserModel, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
17
19
|
[key: string]: any;
|
|
18
20
|
data: UserModel;
|
|
21
|
+
} : ResponseWrapper extends {
|
|
22
|
+
data: UserModel;
|
|
23
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
24
|
+
data: UserModel;
|
|
19
25
|
}>;
|
|
20
|
-
login(username: string, password: string): import("../interfaces/request").RequestProxyResult<TLogin, {
|
|
26
|
+
login(username: string, password: string): import("../interfaces/request").RequestProxyResult<TLogin, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
21
27
|
[key: string]: any;
|
|
22
28
|
data: TLogin;
|
|
29
|
+
} : ResponseWrapper extends {
|
|
30
|
+
data: TLogin;
|
|
31
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
32
|
+
data: TLogin;
|
|
23
33
|
}>;
|
|
24
34
|
checkTokenValid(token: string): import("../interfaces/request").RequestProxyResult<{
|
|
25
35
|
ok: number;
|
|
26
36
|
isGuest: boolean;
|
|
27
|
-
}, {
|
|
37
|
+
}, ResponseWrapper, ResponseWrapper extends unknown ? {
|
|
28
38
|
[key: string]: any;
|
|
29
39
|
data: {
|
|
30
40
|
ok: number;
|
|
31
41
|
isGuest: boolean;
|
|
32
42
|
};
|
|
43
|
+
} : ResponseWrapper extends {
|
|
44
|
+
data: {
|
|
45
|
+
ok: number;
|
|
46
|
+
isGuest: boolean;
|
|
47
|
+
};
|
|
48
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
49
|
+
data: {
|
|
50
|
+
ok: number;
|
|
51
|
+
isGuest: boolean;
|
|
52
|
+
};
|
|
33
53
|
}>;
|
|
34
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../controllers/user.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../controllers/user.ts"],"names":[],"mappings":";;;AAIA,iDAA4C;AAa5C,MAAa,cAAc;IACzB,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAI/C,SAAI,GAAG,QAAQ,CAAA;QAEf,SAAI,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QALvB,IAAA,oBAAQ,EAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAMD,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAa,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,QAAgB,EAAE,QAAgB;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAS;YACnC,IAAI,EAAE;gBACJ,QAAQ;gBACR,QAAQ;aACT;SACF,CAAC,CAAA;IACJ,CAAC;IAED,eAAe,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAmC;YACnE,MAAM,EAAE;gBACN,KAAK,EAAE,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;aACnD;SACF,CAAC,CAAA;IACJ,CAAC;CACF;AAjCD,wCAiCC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { HTTPClient } from '.';
|
|
2
|
-
export declare function attachRequestMethod<T extends HTTPClient
|
|
2
|
+
export declare function attachRequestMethod<T extends HTTPClient<any, any>>(target: T): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-request.js","sourceRoot":"","sources":["../../core/attach-request.ts"],"names":[],"mappings":";;;AAEA,SAAgB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"attach-request.js","sourceRoot":"","sources":["../../core/attach-request.ts"],"names":[],"mappings":";;;AAEA,SAAgB,mBAAmB,CAAiC,MAAS;IAC3E,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE;QACrC,KAAK,EAAE,UAAU,GAAW,EAAE,OAAa;YACzC,8CAA8C;YAC9C,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,OAAO,CAAA;YAC/B,MAAM,EAAE,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAA;YAErC,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QAChE,CAAC;KACF,CAAC,CACD;IAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAW,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAChE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM,EAAE;YAC3C,KAAK,EAAE,UAAU,IAAY,EAAE,OAAa;gBAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;YAC/C,CAAC;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAjBD,kDAiBC;AACD,mCAAmC;AACnC,SAAS,kBAAkB,CAAC,GAA6C;IACvE,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACnC,MAAM,IAAI,SAAS,CAAC,wBAAwB,CAAC,CAAA;KAC9C;IAED,IAAI,GAAG,YAAY,eAAe,EAAE;QAClC,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;KACtB;IACD,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA;IAEpC,MAAM,CAAC,OAAO,CAAM,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;QAC1C,IACE,OAAO,CAAC,KAAK,WAAW;YACxB,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,eAAe,EACrD;YACA,OAAM;SACP;QACD,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAClB,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAA;AAC1B,CAAC"}
|
package/lib/core/client.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { IRequestAdapter } from '../interfaces/adapter';
|
|
1
|
+
import { IAdaptorRequestResponseType, IRequestAdapter } from '../interfaces/adapter';
|
|
2
2
|
import { ClientOptions } from '../interfaces/client';
|
|
3
3
|
import { IController } from '../interfaces/controller';
|
|
4
4
|
import { IRequestHandler } from '../interfaces/request';
|
|
5
|
-
import { Class } from '../types
|
|
6
|
-
export
|
|
5
|
+
import { Class } from '../interfaces/types';
|
|
6
|
+
export type { HTTPClient };
|
|
7
|
+
declare class HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
7
8
|
private _endpoint;
|
|
8
9
|
private _adaptor;
|
|
9
10
|
private _proxy;
|
|
@@ -18,9 +19,11 @@ export declare class HTTPClient<T extends IRequestAdapter = IRequestAdapter> {
|
|
|
18
19
|
method?: string;
|
|
19
20
|
data?: any;
|
|
20
21
|
params?: any;
|
|
21
|
-
}): any
|
|
22
|
-
get proxy(): IRequestHandler
|
|
22
|
+
}): Promise<IAdaptorRequestResponseType<any>>;
|
|
23
|
+
get proxy(): IRequestHandler<ResponseWrapper>;
|
|
23
24
|
private resolveFullPath;
|
|
24
25
|
private buildRoute;
|
|
25
26
|
}
|
|
26
|
-
export declare function createClient<T extends IRequestAdapter>(adapter: T):
|
|
27
|
+
export declare function createClient<T extends IRequestAdapter>(adapter: T): <ResponseWrapper = T extends {
|
|
28
|
+
responseWrapper: infer Type;
|
|
29
|
+
} ? Type extends undefined ? unknown : Type : unknown>(endpoint: string, options?: ClientOptions | undefined) => HTTPClient<T, ResponseWrapper>;
|
package/lib/core/client.js
CHANGED
|
@@ -3,52 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createClient =
|
|
6
|
+
exports.createClient = void 0;
|
|
7
7
|
const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const controllers_1 = require("../controllers");
|
|
10
10
|
const attach_request_1 = require("./attach-request");
|
|
11
11
|
const error_1 = require("./error");
|
|
12
|
-
// export interface HTTPClient {
|
|
13
|
-
// aggregate: AggregateController
|
|
14
|
-
// category: CategoryController
|
|
15
|
-
// comment: CommentController
|
|
16
|
-
// link: LinkController
|
|
17
|
-
// note: NoteController
|
|
18
|
-
// page: PageController
|
|
19
|
-
// post: PostController
|
|
20
|
-
// project: ProjectController
|
|
21
|
-
// recently: RecentlyController
|
|
22
|
-
// say: SayController
|
|
23
|
-
// search: SearchController
|
|
24
|
-
// snippet: SnippetController
|
|
25
|
-
// user: UserController
|
|
26
|
-
// master: HTTPClient['user']
|
|
27
|
-
// friend: HTTPClient['link']
|
|
28
|
-
// shorthand: HTTPClient['recently']
|
|
29
|
-
// }
|
|
30
12
|
const methodPrefix = '_$';
|
|
31
13
|
class HTTPClient {
|
|
32
14
|
constructor(_endpoint, _adaptor) {
|
|
33
15
|
this._endpoint = _endpoint;
|
|
34
16
|
this._adaptor = _adaptor;
|
|
35
|
-
// super()
|
|
36
17
|
this._endpoint = _endpoint
|
|
37
18
|
.replace(/\/*$/, '')
|
|
38
19
|
.replace('localhost', '127.0.0.1');
|
|
39
20
|
this._proxy = this.buildRoute(this)();
|
|
40
21
|
this.initGetClient();
|
|
41
22
|
(0, attach_request_1.attachRequestMethod)(this);
|
|
42
|
-
// const proxy = new Proxy(this, {
|
|
43
|
-
// get(target, key, r) {
|
|
44
|
-
// return (
|
|
45
|
-
// Reflect.get(target, key, r) ||
|
|
46
|
-
// (typeof key === 'string' &&
|
|
47
|
-
// Reflect.get(target, methodPrefix + key, r))
|
|
48
|
-
// )
|
|
49
|
-
// },
|
|
50
|
-
// })
|
|
51
|
-
// return proxy
|
|
52
23
|
}
|
|
53
24
|
initGetClient() {
|
|
54
25
|
for (const name of controllers_1.allContollerNames) {
|
|
@@ -116,7 +87,6 @@ class HTTPClient {
|
|
|
116
87
|
'inspect',
|
|
117
88
|
'constructor',
|
|
118
89
|
Symbol.toPrimitive,
|
|
119
|
-
Symbol.for('util.inspect.custom'),
|
|
120
90
|
];
|
|
121
91
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
122
92
|
const that = this;
|
|
@@ -125,7 +95,18 @@ class HTTPClient {
|
|
|
125
95
|
const handler = {
|
|
126
96
|
get(target, name) {
|
|
127
97
|
if (reflectors.includes(name))
|
|
128
|
-
return () =>
|
|
98
|
+
return (withBase) => {
|
|
99
|
+
if (withBase) {
|
|
100
|
+
const path = that.resolveFullPath(route.join('/'));
|
|
101
|
+
route.length = 0;
|
|
102
|
+
return path;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const path = route.join('/');
|
|
106
|
+
route.length = 0;
|
|
107
|
+
return path.startsWith('/') ? path : '/' + path;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
129
110
|
if (methods.includes(name)) {
|
|
130
111
|
return async (options) => {
|
|
131
112
|
const url = that.resolveFullPath(route.join('/'));
|
|
@@ -190,7 +171,6 @@ class HTTPClient {
|
|
|
190
171
|
};
|
|
191
172
|
}
|
|
192
173
|
}
|
|
193
|
-
exports.HTTPClient = HTTPClient;
|
|
194
174
|
function createClient(adapter) {
|
|
195
175
|
return (endpoint, options) => {
|
|
196
176
|
const client = new HTTPClient(endpoint, adapter);
|
package/lib/core/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../core/client.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA0C;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../core/client.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA0C;AAU1C,mCAAuC;AACvC,gDAAkD;AAClD,qDAAsD;AACtD,mCAAsC;AAEtC,MAAM,YAAY,GAAG,IAAI,CAAA;AAEzB,MAAM,UAAU;IAMd,YAAoB,SAAiB,EAAU,QAAW;QAAtC,cAAS,GAAT,SAAS,CAAQ;QAAU,aAAQ,GAAR,QAAQ,CAAG;QACxD,IAAI,CAAC,SAAS,GAAG,SAAS;aACvB,OAAO,CAAC,MAAM,EAA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AAC,CAAA;gBACjC,CAAC;gBACD,aAAa;gBACb,KAAK,CAAC,MAAW,EAAE,CAAC,EAAE,IAAI;oBACxB,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAA;oBACrD,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;gBACjC,CAAC;aACF,CAAA;YAED,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAQ,CAAA;QACxC,CAAC,CAAA;IACH,CAAC;CACF;AAED,SAAgB,YAAY,CAA4B,OAAU;IAChE,OAAO,CAOL,QAAgB,EAChB,OAAuB,EACvB,EAAE;QACF,MAAM,MAAM,GAAG,IAAI,UAAU,CAAqB,QAAQ,EAAE,OAAO,CAAC,CAAA;QACpE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;QACrC,IAAI,WAAW,EAAE;YACf,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAA;SACtC;QACD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAlBD,oCAkBC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _camelcaseKeys from 'camelcase-keys';
|
|
2
2
|
export * from './controllers';
|
|
3
|
-
export { createClient,
|
|
3
|
+
export { createClient, RequestError } from './core';
|
|
4
|
+
export type { HTTPClient } from './core';
|
|
4
5
|
export * from './models';
|
|
5
6
|
export declare const camelcaseKeysDeep: <T>(obj: T) => T;
|
|
6
7
|
export declare const camelcaseKeys: typeof _camelcaseKeys;
|
package/lib/index.js
CHANGED
|
@@ -13,12 +13,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.camelcaseKeys = exports.camelcaseKeysDeep = exports.RequestError = exports.
|
|
16
|
+
exports.camelcaseKeys = exports.camelcaseKeysDeep = exports.RequestError = exports.createClient = void 0;
|
|
17
17
|
const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
|
|
18
18
|
__exportStar(require("./controllers"), exports);
|
|
19
19
|
var core_1 = require("./core");
|
|
20
20
|
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return core_1.createClient; } });
|
|
21
|
-
Object.defineProperty(exports, "HTTPClient", { enumerable: true, get: function () { return core_1.HTTPClient; } });
|
|
22
21
|
Object.defineProperty(exports, "RequestError", { enumerable: true, get: function () { return core_1.RequestError; } });
|
|
23
22
|
__exportStar(require("./models"), exports);
|
|
24
23
|
// export helper lib
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAA2C;AAE3C,gDAA6B;AAC7B,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAA2C;AAE3C,gDAA6B;AAC7B,+BAAmD;AAA1C,oGAAA,YAAY,OAAA;AAAE,oGAAA,YAAY,OAAA;AAEnC,2CAAwB;AAExB,oBAAoB;AACb,MAAM,iBAAiB,GAAG,CAAI,GAAM,EAAE,EAAE;IAC7C,OAAO,IAAA,qBAAa,EAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAM,CAAA;AAChD,CAAC,CAAA;AAFY,QAAA,iBAAiB,qBAE7B;AAEY,QAAA,aAAa,GAAG,wBAAc,CAAA"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { RequestOptions } from './instance';
|
|
2
|
-
declare type
|
|
2
|
+
export declare type IAdaptorRequestResponseType<P> = Promise<Record<string, any> & {
|
|
3
3
|
data: P;
|
|
4
4
|
}>;
|
|
5
|
-
export declare type IRequestAdapter<T = any> = Readonly<{
|
|
5
|
+
export declare type IRequestAdapter<T = any, Response = undefined> = Readonly<(Response extends undefined ? {} : {
|
|
6
|
+
responseWrapper: Response;
|
|
7
|
+
}) & {
|
|
6
8
|
default: T;
|
|
7
|
-
get<P = unknown>(url: string, options?: Omit<RequestOptions, 'data'>):
|
|
8
|
-
post<P = unknown>(url: string, options: Partial<RequestOptions>):
|
|
9
|
-
patch<P = unknown>(url: string, options: Partial<RequestOptions>):
|
|
10
|
-
delete<P = unknown>(url: string, options?: Omit<RequestOptions, 'data'>):
|
|
11
|
-
put<P = unknown>(url: string, options: Partial<RequestOptions>):
|
|
9
|
+
get<P = unknown>(url: string, options?: Omit<RequestOptions, 'data'>): IAdaptorRequestResponseType<P>;
|
|
10
|
+
post<P = unknown>(url: string, options: Partial<RequestOptions>): IAdaptorRequestResponseType<P>;
|
|
11
|
+
patch<P = unknown>(url: string, options: Partial<RequestOptions>): IAdaptorRequestResponseType<P>;
|
|
12
|
+
delete<P = unknown>(url: string, options?: Omit<RequestOptions, 'data'>): IAdaptorRequestResponseType<P>;
|
|
13
|
+
put<P = unknown>(url: string, options: Partial<RequestOptions>): IAdaptorRequestResponseType<P>;
|
|
12
14
|
}>;
|
|
13
|
-
export {};
|