@mx-space/api-client 0.7.4 → 0.8.0
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/umi-request.ts +1 -1
- package/build/index.cjs.js +26 -16
- 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 +26 -16
- 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 +26 -16
- 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 +1 -1
- package/controllers/base.ts +1 -1
- package/controllers/category.ts +10 -10
- package/controllers/comment.ts +2 -2
- package/controllers/link.ts +17 -2
- package/controllers/note.ts +1 -1
- package/controllers/page.ts +1 -1
- package/controllers/post.ts +1 -1
- package/controllers/project.ts +2 -2
- package/controllers/recently.ts +1 -1
- package/controllers/say.ts +2 -2
- package/controllers/search.ts +2 -2
- package/controllers/severless.ts +1 -1
- package/controllers/snippet.ts +1 -1
- package/controllers/user.ts +2 -2
- package/core/attach-request.ts +4 -4
- package/core/client.ts +8 -14
- package/coverage/clover.xml +144 -136
- package/coverage/coverage-final.json +23 -22
- package/coverage/lcov-report/adaptors/axios.ts.html +1 -1
- package/coverage/lcov-report/adaptors/index.html +1 -1
- package/coverage/lcov-report/adaptors/umi-request.ts.html +2 -2
- package/coverage/lcov-report/controllers/aggregate.ts.html +4 -4
- package/coverage/lcov-report/controllers/base.ts.html +5 -5
- package/coverage/lcov-report/controllers/category.ts.html +16 -16
- package/coverage/lcov-report/controllers/comment.ts.html +5 -5
- package/coverage/lcov-report/controllers/index.html +10 -10
- package/coverage/lcov-report/controllers/index.ts.html +1 -1
- package/coverage/lcov-report/controllers/link.ts.html +54 -9
- package/coverage/lcov-report/controllers/note.ts.html +4 -4
- package/coverage/lcov-report/controllers/page.ts.html +4 -4
- package/coverage/lcov-report/controllers/post.ts.html +4 -4
- package/coverage/lcov-report/controllers/project.ts.html +5 -5
- package/coverage/lcov-report/controllers/recently.ts.html +4 -4
- package/coverage/lcov-report/controllers/say.ts.html +5 -5
- package/coverage/lcov-report/controllers/search.ts.html +5 -5
- package/coverage/lcov-report/controllers/severless.ts.html +4 -4
- package/coverage/lcov-report/controllers/snippet.ts.html +4 -4
- package/coverage/lcov-report/controllers/user.ts.html +5 -5
- package/coverage/lcov-report/core/attach-request.ts.html +14 -14
- package/coverage/lcov-report/core/client.ts.html +46 -64
- package/coverage/lcov-report/core/error.ts.html +1 -1
- package/coverage/lcov-report/core/index.html +15 -15
- package/coverage/lcov-report/core/index.ts.html +1 -1
- package/coverage/lcov-report/index.html +31 -31
- 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 +10 -10
- package/coverage/lcov-report/utils/index.html +24 -9
- package/coverage/lcov-report/utils/index.ts.html +3 -3
- package/coverage/lcov-report/utils/path.ts.html +103 -0
- package/coverage/lcov.info +260 -242
- package/esm/adaptors/umi-request.js.map +1 -1
- package/esm/controllers/aggregate.d.ts +1 -1
- package/esm/controllers/aggregate.js.map +1 -1
- package/esm/controllers/base.d.ts +1 -1
- package/esm/controllers/base.js.map +1 -1
- package/esm/controllers/category.d.ts +6 -6
- package/esm/controllers/category.js +3 -3
- package/esm/controllers/category.js.map +1 -1
- package/esm/controllers/comment.d.ts +2 -2
- package/esm/controllers/comment.js.map +1 -1
- package/esm/controllers/link.d.ts +6 -2
- package/esm/controllers/link.js +10 -1
- package/esm/controllers/link.js.map +1 -1
- package/esm/controllers/note.d.ts +1 -1
- package/esm/controllers/note.js.map +1 -1
- package/esm/controllers/page.d.ts +1 -1
- package/esm/controllers/page.js.map +1 -1
- package/esm/controllers/post.d.ts +1 -1
- package/esm/controllers/post.js.map +1 -1
- package/esm/controllers/project.d.ts +2 -2
- package/esm/controllers/project.js +1 -1
- package/esm/controllers/project.js.map +1 -1
- package/esm/controllers/recently.d.ts +1 -1
- package/esm/controllers/recently.js.map +1 -1
- package/esm/controllers/say.d.ts +2 -2
- package/esm/controllers/say.js +1 -1
- package/esm/controllers/say.js.map +1 -1
- package/esm/controllers/search.d.ts +50 -50
- package/esm/controllers/search.js.map +1 -1
- package/esm/controllers/severless.d.ts +1 -1
- package/esm/controllers/severless.js.map +1 -1
- package/esm/controllers/snippet.d.ts +1 -1
- package/esm/controllers/snippet.js.map +1 -1
- package/esm/controllers/user.d.ts +1 -1
- package/esm/controllers/user.js +1 -1
- package/esm/controllers/user.js.map +1 -1
- package/esm/core/attach-request.js +4 -4
- package/esm/core/attach-request.js.map +1 -1
- package/esm/core/client.d.ts +0 -1
- package/esm/core/client.js +6 -11
- package/esm/core/client.js.map +1 -1
- package/esm/models/link.d.ts +1 -0
- package/esm/utils/path.d.ts +1 -0
- package/esm/utils/path.js +7 -0
- package/esm/utils/path.js.map +1 -0
- package/interfaces/request.ts +2 -2
- package/lib/controllers/aggregate.d.ts +1 -1
- package/lib/controllers/aggregate.js.map +1 -1
- package/lib/controllers/base.d.ts +1 -1
- package/lib/controllers/base.js.map +1 -1
- package/lib/controllers/category.d.ts +6 -6
- package/lib/controllers/category.js +3 -3
- package/lib/controllers/category.js.map +1 -1
- package/lib/controllers/comment.d.ts +2 -2
- package/lib/controllers/comment.js.map +1 -1
- package/lib/controllers/link.d.ts +6 -2
- package/lib/controllers/link.js +10 -1
- package/lib/controllers/link.js.map +1 -1
- package/lib/controllers/note.d.ts +1 -1
- package/lib/controllers/note.js.map +1 -1
- package/lib/controllers/page.d.ts +1 -1
- package/lib/controllers/page.js.map +1 -1
- package/lib/controllers/post.d.ts +1 -1
- package/lib/controllers/post.js.map +1 -1
- package/lib/controllers/project.d.ts +2 -2
- package/lib/controllers/project.js +1 -1
- package/lib/controllers/project.js.map +1 -1
- package/lib/controllers/recently.d.ts +1 -1
- package/lib/controllers/recently.js.map +1 -1
- package/lib/controllers/say.d.ts +2 -2
- package/lib/controllers/say.js +1 -1
- package/lib/controllers/say.js.map +1 -1
- package/lib/controllers/search.d.ts +50 -50
- package/lib/controllers/search.js.map +1 -1
- package/lib/controllers/severless.d.ts +1 -1
- package/lib/controllers/severless.js.map +1 -1
- package/lib/controllers/snippet.d.ts +1 -1
- package/lib/controllers/snippet.js.map +1 -1
- package/lib/controllers/user.d.ts +1 -1
- package/lib/controllers/user.js +1 -1
- package/lib/controllers/user.js.map +1 -1
- package/lib/core/attach-request.js +4 -4
- package/lib/core/attach-request.js.map +1 -1
- package/lib/core/client.d.ts +0 -1
- package/lib/core/client.js +6 -11
- package/lib/core/client.js.map +1 -1
- package/lib/models/link.d.ts +1 -0
- package/lib/utils/path.d.ts +1 -0
- package/lib/utils/path.js +11 -0
- package/lib/utils/path.js.map +1 -0
- package/models/link.ts +1 -0
- package/package.json +3 -2
- package/types/controllers/aggregate.d.ts +1 -1
- package/types/controllers/base.d.ts +1 -1
- package/types/controllers/category.d.ts +6 -6
- package/types/controllers/comment.d.ts +2 -2
- package/types/controllers/link.d.ts +6 -2
- package/types/controllers/note.d.ts +1 -1
- package/types/controllers/page.d.ts +1 -1
- package/types/controllers/post.d.ts +1 -1
- package/types/controllers/project.d.ts +2 -2
- package/types/controllers/recently.d.ts +1 -1
- package/types/controllers/say.d.ts +2 -2
- package/types/controllers/search.d.ts +50 -50
- package/types/controllers/severless.d.ts +1 -1
- package/types/controllers/snippet.d.ts +1 -1
- package/types/controllers/user.d.ts +1 -1
- package/types/core/client.d.ts +0 -1
- package/types/models/link.d.ts +1 -0
- package/types/utils/path.d.ts +1 -0
- package/utils/path.ts +6 -0
package/controllers/page.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HTTPClient } from '../core'
|
|
1
2
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
3
|
import { IController } from '~/interfaces/controller'
|
|
3
4
|
import { IRequestHandler } from '~/interfaces/request'
|
|
@@ -5,7 +6,6 @@ import { SelectFields } from '~/interfaces/types'
|
|
|
5
6
|
import { PaginateResult } from '~/models/base'
|
|
6
7
|
import { PageModel } from '~/models/page'
|
|
7
8
|
import { autoBind } from '~/utils/auto-bind'
|
|
8
|
-
import { HTTPClient } from '../core'
|
|
9
9
|
|
|
10
10
|
declare module '../core/client' {
|
|
11
11
|
interface HTTPClient<
|
package/controllers/post.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HTTPClient } from '../core/client'
|
|
1
2
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
3
|
import { IController } from '~/interfaces/controller'
|
|
3
4
|
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
@@ -5,7 +6,6 @@ import { SelectFields } from '~/interfaces/types'
|
|
|
5
6
|
import { PaginateResult } from '~/models/base'
|
|
6
7
|
import { PostModel } from '~/models/post'
|
|
7
8
|
import { autoBind } from '~/utils/auto-bind'
|
|
8
|
-
import { HTTPClient } from '../core/client'
|
|
9
9
|
|
|
10
10
|
declare module '../core/client' {
|
|
11
11
|
interface HTTPClient<
|
package/controllers/project.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { HTTPClient } from '../core'
|
|
2
|
+
import { BaseCrudController } from './base'
|
|
1
3
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
4
|
import { ProjectModel } from '~/models/project'
|
|
3
5
|
import { autoBind } from '~/utils/auto-bind'
|
|
4
|
-
import { HTTPClient } from '../core'
|
|
5
|
-
import { BaseCrudController } from './base'
|
|
6
6
|
|
|
7
7
|
declare module '../core/client' {
|
|
8
8
|
interface HTTPClient<
|
package/controllers/recently.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { HTTPClient } from '../core'
|
|
1
2
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
3
|
import { IController } from '~/interfaces/controller'
|
|
3
4
|
import { IRequestHandler } from '~/interfaces/request'
|
|
4
5
|
import { RecentlyModel } from '~/models/recently'
|
|
5
6
|
import { autoBind } from '~/utils/auto-bind'
|
|
6
|
-
import { HTTPClient } from '../core'
|
|
7
7
|
|
|
8
8
|
declare module '../core/client' {
|
|
9
9
|
interface HTTPClient<
|
package/controllers/say.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { HTTPClient } from '../core'
|
|
2
|
+
import { BaseCrudController } from './base'
|
|
1
3
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
4
|
import { IController } from '~/interfaces/controller'
|
|
3
5
|
import { IRequestHandler } from '~/interfaces/request'
|
|
4
6
|
import { SayModel } from '~/models/say'
|
|
5
7
|
import { autoBind } from '~/utils/auto-bind'
|
|
6
|
-
import { HTTPClient } from '../core'
|
|
7
|
-
import { BaseCrudController } from './base'
|
|
8
8
|
|
|
9
9
|
declare module '../core/client' {
|
|
10
10
|
interface HTTPClient<
|
package/controllers/search.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PageModel } from '..'
|
|
2
|
+
import { HTTPClient } from '../core'
|
|
1
3
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
4
|
import { IController } from '~/interfaces/controller'
|
|
3
5
|
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
@@ -5,8 +7,6 @@ import { PaginateResult } from '~/models/base'
|
|
|
5
7
|
import { NoteModel } from '~/models/note'
|
|
6
8
|
import { PostModel } from '~/models/post'
|
|
7
9
|
import { autoBind } from '~/utils/auto-bind'
|
|
8
|
-
import { PageModel } from '..'
|
|
9
|
-
import { HTTPClient } from '../core'
|
|
10
10
|
|
|
11
11
|
declare module '../core/client' {
|
|
12
12
|
interface HTTPClient<
|
package/controllers/severless.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { HTTPClient } from '../core'
|
|
1
2
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
3
|
import { IController } from '~/interfaces/controller'
|
|
3
4
|
import { IRequestHandler } from '~/interfaces/request'
|
|
4
5
|
import { autoBind } from '~/utils/auto-bind'
|
|
5
|
-
import { HTTPClient } from '../core'
|
|
6
6
|
|
|
7
7
|
declare module '../core/client' {
|
|
8
8
|
interface HTTPClient<
|
package/controllers/snippet.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { HTTPClient } from '../core'
|
|
1
2
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
3
|
import { IController } from '~/interfaces/controller'
|
|
3
4
|
import { IRequestHandler } from '~/interfaces/request'
|
|
4
5
|
import { SnippetModel } from '~/models/snippet'
|
|
5
6
|
import { autoBind } from '~/utils/auto-bind'
|
|
6
|
-
import { HTTPClient } from '../core'
|
|
7
7
|
|
|
8
8
|
declare module '../core/client' {
|
|
9
9
|
interface HTTPClient<
|
package/controllers/user.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { HTTPClient } from '../core'
|
|
1
2
|
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
3
|
import { IController } from '~/interfaces/controller'
|
|
3
4
|
import { IRequestHandler } from '~/interfaces/request'
|
|
4
5
|
import { TLogin, UserModel } from '~/models/user'
|
|
5
6
|
import { autoBind } from '~/utils/auto-bind'
|
|
6
|
-
import { HTTPClient } from '../core'
|
|
7
7
|
|
|
8
8
|
declare module '../core/client' {
|
|
9
9
|
interface HTTPClient<
|
|
@@ -44,7 +44,7 @@ export class UserController<ResponseWrapper> implements IController {
|
|
|
44
44
|
checkTokenValid(token: string) {
|
|
45
45
|
return this.proxy.check_logged.get<{ ok: number; isGuest: boolean }>({
|
|
46
46
|
params: {
|
|
47
|
-
token:
|
|
47
|
+
token: `bearer ${token.replace(/^Bearer\s/i, '')}`,
|
|
48
48
|
},
|
|
49
49
|
})
|
|
50
50
|
}
|
package/core/attach-request.ts
CHANGED
|
@@ -2,17 +2,17 @@ import type { HTTPClient } from '.'
|
|
|
2
2
|
|
|
3
3
|
export function attachRequestMethod<T extends HTTPClient<any, any>>(target: T) {
|
|
4
4
|
Object.defineProperty(target, '$$get', {
|
|
5
|
-
value
|
|
5
|
+
value(url: string, options?: any) {
|
|
6
6
|
// HINT: method get only accept search params;
|
|
7
7
|
const { params = {} } = options
|
|
8
8
|
const qs = handleSearchParams(params)
|
|
9
9
|
|
|
10
|
-
return target.instance.get(
|
|
10
|
+
return target.instance.get(`${url}${qs ? `${`?${qs}`}` : ''}`)
|
|
11
11
|
},
|
|
12
12
|
})
|
|
13
13
|
;(['put', 'post', 'patch', 'delete'] as const).forEach((method) => {
|
|
14
|
-
Object.defineProperty(target,
|
|
15
|
-
value
|
|
14
|
+
Object.defineProperty(target, `$$${method}`, {
|
|
15
|
+
value(path: string, options?: any) {
|
|
16
16
|
return target.instance[method](path, options)
|
|
17
17
|
},
|
|
18
18
|
})
|
package/core/client.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import camelcaseKeys from 'camelcase-keys'
|
|
2
|
+
import { allContollerNames } from '../controllers'
|
|
3
|
+
import { attachRequestMethod } from './attach-request'
|
|
4
|
+
import { RequestError } from './error'
|
|
2
5
|
import {
|
|
3
6
|
IAdaptorRequestResponseType,
|
|
4
7
|
IRequestAdapter,
|
|
@@ -9,9 +12,7 @@ import { RequestOptions } from '~/interfaces/instance'
|
|
|
9
12
|
import { IRequestHandler, Method } from '~/interfaces/request'
|
|
10
13
|
import { Class } from '~/interfaces/types'
|
|
11
14
|
import { isPlainObject } from '~/utils'
|
|
12
|
-
import {
|
|
13
|
-
import { attachRequestMethod } from './attach-request'
|
|
14
|
-
import { RequestError } from './error'
|
|
15
|
+
import { resolveFullPath } from '~/utils/path'
|
|
15
16
|
|
|
16
17
|
const methodPrefix = '_$'
|
|
17
18
|
export type { HTTPClient }
|
|
@@ -93,7 +94,7 @@ class HTTPClient<
|
|
|
93
94
|
data?: any
|
|
94
95
|
params?: any
|
|
95
96
|
}) {
|
|
96
|
-
return (this as any)[
|
|
97
|
+
return (this as any)[`$$${String(options.method || 'get').toLowerCase()}`](
|
|
97
98
|
options.url,
|
|
98
99
|
options,
|
|
99
100
|
) as Promise<IAdaptorRequestResponseType<any>>
|
|
@@ -103,13 +104,6 @@ class HTTPClient<
|
|
|
103
104
|
return this._proxy
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
private resolveFullPath(path: string) {
|
|
107
|
-
if (!path.startsWith('/')) {
|
|
108
|
-
path = '/' + path
|
|
109
|
-
}
|
|
110
|
-
return `${this.endpoint}${path}`
|
|
111
|
-
}
|
|
112
|
-
|
|
113
107
|
private buildRoute(manager: this): () => IRequestHandler<ResponseWrapper> {
|
|
114
108
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
115
109
|
const noop = () => {}
|
|
@@ -132,18 +126,18 @@ class HTTPClient<
|
|
|
132
126
|
if (reflectors.includes(name))
|
|
133
127
|
return (withBase?: boolean) => {
|
|
134
128
|
if (withBase) {
|
|
135
|
-
const path = that.
|
|
129
|
+
const path = resolveFullPath(that.endpoint, route.join('/'))
|
|
136
130
|
route.length = 0
|
|
137
131
|
return path
|
|
138
132
|
} else {
|
|
139
133
|
const path = route.join('/')
|
|
140
134
|
route.length = 0
|
|
141
|
-
return path.startsWith('/') ? path :
|
|
135
|
+
return path.startsWith('/') ? path : `/${path}`
|
|
142
136
|
}
|
|
143
137
|
}
|
|
144
138
|
if (methods.includes(name)) {
|
|
145
139
|
return async (options: RequestOptions) => {
|
|
146
|
-
const url = that.
|
|
140
|
+
const url = resolveFullPath(that.endpoint, route.join('/'))
|
|
147
141
|
route.length = 0
|
|
148
142
|
let res: Record<string, any> & { data: any }
|
|
149
143
|
try {
|