@mx-space/api-client 0.6.3 → 0.7.0-alpha.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/build/index.cjs.js +18 -0
- package/build/index.cjs.js.map +1 -1
- package/build/index.cjs.min.js.map +1 -1
- package/build/index.d.ts +42 -18
- package/build/index.esm.js +18 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.esm.min.js.map +1 -1
- package/build/index.umd.js +18 -0
- package/build/index.umd.js.map +1 -1
- package/build/index.umd.min.js.map +1 -1
- package/esm/controllers/aggregate.d.ts +5 -0
- package/esm/controllers/aggregate.js.map +1 -1
- package/esm/controllers/category.d.ts +5 -0
- package/esm/controllers/category.js.map +1 -1
- package/esm/controllers/comment.d.ts +5 -0
- package/esm/controllers/comment.js.map +1 -1
- package/esm/controllers/link.d.ts +6 -0
- package/esm/controllers/link.js.map +1 -1
- package/esm/controllers/note.d.ts +5 -0
- package/esm/controllers/note.js.map +1 -1
- package/esm/controllers/page.d.ts +5 -0
- package/esm/controllers/page.js.map +1 -1
- package/esm/controllers/post.d.ts +5 -0
- package/esm/controllers/post.js.map +1 -1
- package/esm/controllers/project.d.ts +5 -0
- package/esm/controllers/project.js.map +1 -1
- package/esm/controllers/recently.d.ts +6 -0
- package/esm/controllers/recently.js.map +1 -1
- package/esm/controllers/say.d.ts +5 -0
- package/esm/controllers/say.js.map +1 -1
- package/esm/controllers/search.d.ts +7 -2
- package/esm/controllers/search.js.map +1 -1
- package/esm/controllers/snippet.d.ts +5 -0
- package/esm/controllers/snippet.js.map +1 -1
- package/esm/controllers/user.d.ts +6 -0
- package/esm/controllers/user.js.map +1 -1
- package/esm/core/client.d.ts +0 -19
- package/esm/core/client.js +19 -1
- package/esm/core/client.js.map +1 -1
- package/lib/controllers/aggregate.d.ts +5 -0
- package/lib/controllers/aggregate.js.map +1 -1
- package/lib/controllers/category.d.ts +5 -0
- package/lib/controllers/category.js.map +1 -1
- package/lib/controllers/comment.d.ts +5 -0
- package/lib/controllers/comment.js.map +1 -1
- package/lib/controllers/link.d.ts +6 -0
- package/lib/controllers/link.js.map +1 -1
- package/lib/controllers/note.d.ts +5 -0
- package/lib/controllers/note.js.map +1 -1
- package/lib/controllers/page.d.ts +5 -0
- package/lib/controllers/page.js.map +1 -1
- package/lib/controllers/post.d.ts +5 -0
- package/lib/controllers/post.js.map +1 -1
- package/lib/controllers/project.d.ts +5 -0
- package/lib/controllers/project.js.map +1 -1
- package/lib/controllers/recently.d.ts +6 -0
- package/lib/controllers/recently.js.map +1 -1
- package/lib/controllers/say.d.ts +5 -0
- package/lib/controllers/say.js.map +1 -1
- package/lib/controllers/search.d.ts +7 -2
- package/lib/controllers/search.js.map +1 -1
- package/lib/controllers/snippet.d.ts +5 -0
- package/lib/controllers/snippet.js.map +1 -1
- package/lib/controllers/user.d.ts +6 -0
- package/lib/controllers/user.js.map +1 -1
- package/lib/core/client.d.ts +0 -19
- package/lib/core/client.js +18 -0
- package/lib/core/client.js.map +1 -1
- package/package.json +11 -4
- package/src/adaptors/axios.ts +36 -0
- package/src/adaptors/umi-request.ts +30 -0
- package/src/controllers/aggregate.ts +65 -0
- package/src/controllers/base.ts +32 -0
- package/src/controllers/category.ts +107 -0
- package/src/controllers/comment.ts +64 -0
- package/src/controllers/index.ts +66 -0
- package/src/controllers/link.ts +21 -0
- package/src/controllers/note.ts +92 -0
- package/src/controllers/page.ts +59 -0
- package/src/controllers/post.ts +87 -0
- package/src/controllers/project.ts +20 -0
- package/src/controllers/recently.ts +48 -0
- package/src/controllers/say.ts +35 -0
- package/src/controllers/search.ts +101 -0
- package/src/controllers/snippet.ts +31 -0
- package/src/controllers/user.ts +46 -0
- package/src/core/attach-request.ts +43 -0
- package/src/core/client.ts +249 -0
- package/src/core/error.ts +10 -0
- package/src/core/index.ts +2 -0
- package/src/dtos/comment.ts +9 -0
- package/src/index.ts +12 -0
- package/src/interfaces/adapter.ts +30 -0
- package/src/interfaces/client.ts +6 -0
- package/src/interfaces/controller.ts +5 -0
- package/src/interfaces/instance.ts +8 -0
- package/src/interfaces/options.ts +1 -0
- package/src/interfaces/params.ts +4 -0
- package/src/interfaces/request.ts +57 -0
- package/src/models/aggregate.ts +71 -0
- package/src/models/base.ts +43 -0
- package/src/models/category.ts +25 -0
- package/src/models/comment.ts +37 -0
- package/src/models/index.ts +14 -0
- package/src/models/link.ts +23 -0
- package/src/models/note.ts +37 -0
- package/src/models/page.ts +20 -0
- package/src/models/post.ts +16 -0
- package/src/models/project.ts +12 -0
- package/src/models/recently.ts +7 -0
- package/src/models/say.ts +7 -0
- package/src/models/setting.ts +68 -0
- package/src/models/snippet.ts +18 -0
- package/src/models/user.ts +27 -0
- package/src/tsconfig.build.json +6 -0
- package/src/tsconfig.cjs.json +7 -0
- package/src/tsconfig.json +12 -0
- package/src/types/helper.d.ts +3 -0
- package/src/utils/auto-bind.ts +48 -0
- package/src/utils/index.ts +53 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { HTTPClient } from '.'
|
|
2
|
+
|
|
3
|
+
export function attachRequestMethod<T extends HTTPClient>(target: T) {
|
|
4
|
+
Object.defineProperty(target, '$$get', {
|
|
5
|
+
value: function (url: string, options?: any) {
|
|
6
|
+
// HINT: method get only accept search params;
|
|
7
|
+
const { params = {} } = options
|
|
8
|
+
const qs = handleSearchParams(params)
|
|
9
|
+
|
|
10
|
+
return target.instance.get(url + `${qs ? `${'?' + qs}` : ''}`)
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
;(['put', 'post', 'patch', 'delete'] as const).forEach((method) => {
|
|
14
|
+
Object.defineProperty(target, '$$' + method, {
|
|
15
|
+
value: function (path: string, options?: any) {
|
|
16
|
+
return target.instance[method](path, options)
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
// FIXME: only support string value
|
|
22
|
+
function handleSearchParams(obj: URLSearchParams | Record<string, string>) {
|
|
23
|
+
if (!obj && typeof obj !== 'object') {
|
|
24
|
+
throw new TypeError('params must be object.')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (obj instanceof URLSearchParams) {
|
|
28
|
+
return obj.toString()
|
|
29
|
+
}
|
|
30
|
+
const search = new URLSearchParams()
|
|
31
|
+
|
|
32
|
+
Object.entries<any>(obj).forEach(([k, v]) => {
|
|
33
|
+
if (
|
|
34
|
+
typeof v === 'undefined' ||
|
|
35
|
+
Object.prototype.toString.call(v) === '[object Null]'
|
|
36
|
+
) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
search.set(k, v)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return search.toString()
|
|
43
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import camelcaseKeys from 'camelcase-keys'
|
|
2
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
3
|
+
import { ClientOptions } from '~/interfaces/client'
|
|
4
|
+
import { IController } from '~/interfaces/controller'
|
|
5
|
+
import { RequestOptions } from '~/interfaces/instance'
|
|
6
|
+
import { IRequestHandler, Method } from '~/interfaces/request'
|
|
7
|
+
import { Class } from '~/types/helper'
|
|
8
|
+
import { isPlainObject } from '~/utils'
|
|
9
|
+
import { allContollerNames } from '../controllers'
|
|
10
|
+
import { attachRequestMethod } from './attach-request'
|
|
11
|
+
import { RequestError } from './error'
|
|
12
|
+
|
|
13
|
+
// export interface HTTPClient {
|
|
14
|
+
// aggregate: AggregateController
|
|
15
|
+
// category: CategoryController
|
|
16
|
+
// comment: CommentController
|
|
17
|
+
// link: LinkController
|
|
18
|
+
// note: NoteController
|
|
19
|
+
// page: PageController
|
|
20
|
+
// post: PostController
|
|
21
|
+
// project: ProjectController
|
|
22
|
+
// recently: RecentlyController
|
|
23
|
+
// say: SayController
|
|
24
|
+
// search: SearchController
|
|
25
|
+
// snippet: SnippetController
|
|
26
|
+
// user: UserController
|
|
27
|
+
|
|
28
|
+
// master: HTTPClient['user']
|
|
29
|
+
|
|
30
|
+
// friend: HTTPClient['link']
|
|
31
|
+
|
|
32
|
+
// shorthand: HTTPClient['recently']
|
|
33
|
+
// }
|
|
34
|
+
|
|
35
|
+
const methodPrefix = '_$'
|
|
36
|
+
|
|
37
|
+
export class HTTPClient<T extends IRequestAdapter = IRequestAdapter> {
|
|
38
|
+
private _proxy: IRequestHandler
|
|
39
|
+
|
|
40
|
+
constructor(private _endpoint: string, private _adaptor: T) {
|
|
41
|
+
// super()
|
|
42
|
+
this._endpoint = _endpoint
|
|
43
|
+
.replace(/\/*$/, '')
|
|
44
|
+
.replace('localhost', '127.0.0.1')
|
|
45
|
+
this._proxy = this.buildRoute(this)()
|
|
46
|
+
|
|
47
|
+
this.initGetClient()
|
|
48
|
+
|
|
49
|
+
attachRequestMethod(this)
|
|
50
|
+
|
|
51
|
+
// const proxy = new Proxy(this, {
|
|
52
|
+
// get(target, key, r) {
|
|
53
|
+
// return (
|
|
54
|
+
// Reflect.get(target, key, r) ||
|
|
55
|
+
// (typeof key === 'string' &&
|
|
56
|
+
// Reflect.get(target, methodPrefix + key, r))
|
|
57
|
+
// )
|
|
58
|
+
// },
|
|
59
|
+
// })
|
|
60
|
+
|
|
61
|
+
// return proxy
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private initGetClient() {
|
|
65
|
+
for (const name of allContollerNames) {
|
|
66
|
+
Object.defineProperty(this, name, {
|
|
67
|
+
get() {
|
|
68
|
+
const client = Reflect.get(this, `${methodPrefix}${name}`)
|
|
69
|
+
if (!client) {
|
|
70
|
+
throw new ReferenceError(
|
|
71
|
+
`${
|
|
72
|
+
name.charAt(0).toUpperCase() + name.slice(1)
|
|
73
|
+
} Client not inject yet, please inject with client.injectClients(...)`,
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
return client
|
|
77
|
+
},
|
|
78
|
+
configurable: false,
|
|
79
|
+
enumerable: false,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public injectControllers(...Controller: Class<IController>[]): void
|
|
85
|
+
public injectControllers(Controller: Class<IController>[]): void
|
|
86
|
+
public injectControllers(Controller: any, ...rest: any[]) {
|
|
87
|
+
Controller = Array.isArray(Controller) ? Controller : [Controller, ...rest]
|
|
88
|
+
for (const Client of Controller) {
|
|
89
|
+
const cl = new Client(this)
|
|
90
|
+
|
|
91
|
+
if (Array.isArray(cl.name)) {
|
|
92
|
+
for (const name of cl.name) {
|
|
93
|
+
attach.call(this, name, cl)
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
attach.call(this, cl.name, cl)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function attach(this: any, name: string, cl: IController) {
|
|
101
|
+
Object.defineProperty(this, `${methodPrefix}${name.toLowerCase()}`, {
|
|
102
|
+
get() {
|
|
103
|
+
return cl
|
|
104
|
+
},
|
|
105
|
+
enumerable: false,
|
|
106
|
+
configurable: false,
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get endpoint() {
|
|
112
|
+
return this._endpoint
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
get instance() {
|
|
116
|
+
return this._adaptor
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public request(options: {
|
|
120
|
+
url: string
|
|
121
|
+
method?: string
|
|
122
|
+
data?: any
|
|
123
|
+
params?: any
|
|
124
|
+
}) {
|
|
125
|
+
return (this as any)['$$' + String(options.method || 'get').toLowerCase()](
|
|
126
|
+
options.url,
|
|
127
|
+
options,
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public get proxy() {
|
|
132
|
+
return this._proxy
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private resolveFullPath(path: string) {
|
|
136
|
+
if (!path.startsWith('/')) {
|
|
137
|
+
path = '/' + path
|
|
138
|
+
}
|
|
139
|
+
return `${this.endpoint}${path}`
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private buildRoute(manager: this): () => IRequestHandler {
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
144
|
+
const noop = () => {}
|
|
145
|
+
const methods = ['get', 'post', 'delete', 'patch', 'put']
|
|
146
|
+
const reflectors = [
|
|
147
|
+
'toString',
|
|
148
|
+
'valueOf',
|
|
149
|
+
'inspect',
|
|
150
|
+
'constructor',
|
|
151
|
+
Symbol.toPrimitive,
|
|
152
|
+
Symbol.for('util.inspect.custom'),
|
|
153
|
+
]
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
155
|
+
const that = this
|
|
156
|
+
|
|
157
|
+
return () => {
|
|
158
|
+
const route = ['']
|
|
159
|
+
|
|
160
|
+
const handler: any = {
|
|
161
|
+
get(target: any, name: Method) {
|
|
162
|
+
if (reflectors.includes(name)) return () => route.join('/')
|
|
163
|
+
if (methods.includes(name)) {
|
|
164
|
+
return async (options: RequestOptions) => {
|
|
165
|
+
const url = that.resolveFullPath(route.join('/'))
|
|
166
|
+
route.length = 0
|
|
167
|
+
let res: any
|
|
168
|
+
try {
|
|
169
|
+
res = await manager.request({
|
|
170
|
+
method: name,
|
|
171
|
+
...options,
|
|
172
|
+
url,
|
|
173
|
+
})
|
|
174
|
+
} catch (e: any) {
|
|
175
|
+
throw new RequestError(
|
|
176
|
+
e.message,
|
|
177
|
+
e.code ||
|
|
178
|
+
e.status ||
|
|
179
|
+
e.statusCode ||
|
|
180
|
+
e.response?.status ||
|
|
181
|
+
e.response?.statusCode ||
|
|
182
|
+
e.response?.code ||
|
|
183
|
+
500,
|
|
184
|
+
url,
|
|
185
|
+
e,
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const data = res.data
|
|
190
|
+
if (!data) {
|
|
191
|
+
return null
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const transform =
|
|
195
|
+
Array.isArray(data) || isPlainObject(data)
|
|
196
|
+
? camelcaseKeys(data, { deep: true })
|
|
197
|
+
: data
|
|
198
|
+
|
|
199
|
+
if (transform && typeof transform === 'object') {
|
|
200
|
+
Object.defineProperty(transform, '$raw', {
|
|
201
|
+
get() {
|
|
202
|
+
return res
|
|
203
|
+
},
|
|
204
|
+
enumerable: false,
|
|
205
|
+
configurable: false,
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
// attach request config onto response
|
|
209
|
+
|
|
210
|
+
Object.defineProperty(transform, '$request', {
|
|
211
|
+
get() {
|
|
212
|
+
return {
|
|
213
|
+
url,
|
|
214
|
+
method: name,
|
|
215
|
+
options,
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
enumerable: false,
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return transform
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
route.push(name)
|
|
226
|
+
return new Proxy(noop, handler)
|
|
227
|
+
},
|
|
228
|
+
// @ts-ignore
|
|
229
|
+
apply(target: any, _, args) {
|
|
230
|
+
route.push(...args.filter((x: string) => x !== null))
|
|
231
|
+
return new Proxy(noop, handler)
|
|
232
|
+
},
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return new Proxy(noop, handler) as any
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function createClient<T extends IRequestAdapter>(adapter: T) {
|
|
241
|
+
return (endpoint: string, options?: ClientOptions) => {
|
|
242
|
+
const client = new HTTPClient(endpoint, adapter)
|
|
243
|
+
const { controllers } = options || {}
|
|
244
|
+
if (controllers) {
|
|
245
|
+
client.injectControllers(controllers)
|
|
246
|
+
}
|
|
247
|
+
return client
|
|
248
|
+
}
|
|
249
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import _camelcaseKeys from 'camelcase-keys'
|
|
2
|
+
|
|
3
|
+
export * from './controllers'
|
|
4
|
+
export { createClient, HTTPClient, RequestError } from './core'
|
|
5
|
+
export * from './models'
|
|
6
|
+
|
|
7
|
+
// export helper lib
|
|
8
|
+
export const camelcaseKeysDeep = <T>(obj: T) => {
|
|
9
|
+
return camelcaseKeys(obj, { deep: true }) as T
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const camelcaseKeys = _camelcaseKeys
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RequestOptions } from './instance'
|
|
2
|
+
type RequestResponseType<P> = Promise<Record<string, any> & { data: P }>
|
|
3
|
+
|
|
4
|
+
export type IRequestAdapter<T = any> = Readonly<{
|
|
5
|
+
default: T
|
|
6
|
+
get<P = unknown>(
|
|
7
|
+
url: string,
|
|
8
|
+
options?: Omit<RequestOptions, 'data'>,
|
|
9
|
+
): RequestResponseType<P>
|
|
10
|
+
|
|
11
|
+
post<P = unknown>(
|
|
12
|
+
url: string,
|
|
13
|
+
options: Partial<RequestOptions>,
|
|
14
|
+
): RequestResponseType<P>
|
|
15
|
+
|
|
16
|
+
patch<P = unknown>(
|
|
17
|
+
url: string,
|
|
18
|
+
options: Partial<RequestOptions>,
|
|
19
|
+
): RequestResponseType<P>
|
|
20
|
+
|
|
21
|
+
delete<P = unknown>(
|
|
22
|
+
url: string,
|
|
23
|
+
options?: Omit<RequestOptions, 'data'>,
|
|
24
|
+
): RequestResponseType<P>
|
|
25
|
+
|
|
26
|
+
put<P = unknown>(
|
|
27
|
+
url: string,
|
|
28
|
+
options: Partial<RequestOptions>,
|
|
29
|
+
): RequestResponseType<P>
|
|
30
|
+
}>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SortOrder = 'asc' | 'desc'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { RequestOptions } from './instance'
|
|
2
|
+
type NoStringIndex<T> = { [K in keyof T as string extends K ? never : K]: T[K] }
|
|
3
|
+
|
|
4
|
+
export type Method = 'get' | 'delete' | 'post' | 'put' | 'patch'
|
|
5
|
+
|
|
6
|
+
export interface IRequestHandler {
|
|
7
|
+
(path?: string | number): IRequestHandler
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
get<P = unknown>(
|
|
10
|
+
options?: Omit<NoStringIndex<RequestOptions>, 'data'>,
|
|
11
|
+
): RequestProxyResult<P>
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
post<P = unknown>(options?: RequestOptions): RequestProxyResult<P>
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
patch<P = unknown>(options?: RequestOptions): RequestProxyResult<P>
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
delete<P = unknown>(
|
|
18
|
+
options?: Omit<NoStringIndex<RequestOptions>, 'data'>,
|
|
19
|
+
): RequestProxyResult<P>
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
put<P = unknown>(options?: RequestOptions): RequestProxyResult<P>
|
|
22
|
+
[key: string]: IRequestHandler
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type RequestProxyResult<
|
|
26
|
+
T,
|
|
27
|
+
R = { data: T; [key: string]: any },
|
|
28
|
+
> = Promise<ResponseProxyExtraRaw<T, R>>
|
|
29
|
+
|
|
30
|
+
type CamelToSnake<T extends string, P extends string = ''> = string extends T
|
|
31
|
+
? string
|
|
32
|
+
: T extends `${infer C0}${infer R}`
|
|
33
|
+
? CamelToSnake<
|
|
34
|
+
R,
|
|
35
|
+
`${P}${C0 extends Lowercase<C0> ? '' : '_'}${Lowercase<C0>}`
|
|
36
|
+
>
|
|
37
|
+
: P
|
|
38
|
+
|
|
39
|
+
type CamelKeysToSnake<T> = {
|
|
40
|
+
[K in keyof T as CamelToSnake<Extract<K, string>>]: T[K]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ResponseProxyExtraRaw<
|
|
44
|
+
T,
|
|
45
|
+
RawData = unknown,
|
|
46
|
+
Response = unknown,
|
|
47
|
+
> = T extends object
|
|
48
|
+
? T & {
|
|
49
|
+
$raw: Response extends unknown
|
|
50
|
+
? {
|
|
51
|
+
[i: string]: any
|
|
52
|
+
data: RawData extends unknown ? CamelKeysToSnake<T> : RawData
|
|
53
|
+
}
|
|
54
|
+
: Response
|
|
55
|
+
$request: { path: string; method: string; [k: string]: string }
|
|
56
|
+
}
|
|
57
|
+
: T
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { CategoryModel } from './category'
|
|
2
|
+
import { NoteModel } from './note'
|
|
3
|
+
import { PageModel } from './page'
|
|
4
|
+
import { PostModel } from './post'
|
|
5
|
+
import { SayModel } from './say'
|
|
6
|
+
import { SeoOptionModel } from './setting'
|
|
7
|
+
import { UserModel } from './user'
|
|
8
|
+
|
|
9
|
+
export interface AggregateRoot {
|
|
10
|
+
user: UserModel
|
|
11
|
+
seo: SeoOptionModel
|
|
12
|
+
url: Url
|
|
13
|
+
categories: CategoryModel[]
|
|
14
|
+
pageMeta: Pick<PageModel, 'title' | 'id' | 'slug' | 'order'>[] | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Url {
|
|
18
|
+
wsUrl: string
|
|
19
|
+
serverUrl: string
|
|
20
|
+
webUrl: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AggregateTop {
|
|
24
|
+
notes: Pick<NoteModel, 'id' | 'title' | 'created' | 'nid'>[]
|
|
25
|
+
posts: Pick<PostModel, 'id' | 'slug' | 'created' | 'title' | 'category'>[]
|
|
26
|
+
says: SayModel[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export enum TimelineType {
|
|
30
|
+
Post,
|
|
31
|
+
Note,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface TimelineData {
|
|
35
|
+
notes?: Pick<
|
|
36
|
+
NoteModel,
|
|
37
|
+
| 'id'
|
|
38
|
+
| 'nid'
|
|
39
|
+
| 'title'
|
|
40
|
+
| 'weather'
|
|
41
|
+
| 'mood'
|
|
42
|
+
| 'created'
|
|
43
|
+
| 'modified'
|
|
44
|
+
| 'hasMemory'
|
|
45
|
+
>[]
|
|
46
|
+
|
|
47
|
+
posts?: (Pick<
|
|
48
|
+
PostModel,
|
|
49
|
+
'id' | 'title' | 'slug' | 'created' | 'modified' | 'category'
|
|
50
|
+
> & { url: string })[]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface AggregateStat {
|
|
54
|
+
allComments: number
|
|
55
|
+
categories: number
|
|
56
|
+
comments: number
|
|
57
|
+
linkApply: number
|
|
58
|
+
links: number
|
|
59
|
+
notes: number
|
|
60
|
+
pages: number
|
|
61
|
+
posts: number
|
|
62
|
+
says: number
|
|
63
|
+
recently: number
|
|
64
|
+
unreadComments: number
|
|
65
|
+
online: number
|
|
66
|
+
todayMaxOnline: string
|
|
67
|
+
todayOnlineTotal: string
|
|
68
|
+
callTime: number
|
|
69
|
+
uv: number
|
|
70
|
+
todayIPAccessCount: number
|
|
71
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface Count {
|
|
2
|
+
read: number
|
|
3
|
+
like: number
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface Image {
|
|
7
|
+
height: number
|
|
8
|
+
width: number
|
|
9
|
+
type: string
|
|
10
|
+
accent?: string
|
|
11
|
+
src: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Pager {
|
|
15
|
+
total: number
|
|
16
|
+
size: number
|
|
17
|
+
currentPage: number
|
|
18
|
+
totalPage: number
|
|
19
|
+
hasPrevPage: boolean
|
|
20
|
+
hasNextPage: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface PaginateResult<T> {
|
|
24
|
+
data: T[]
|
|
25
|
+
pagination: Pager
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface BaseModel {
|
|
29
|
+
created: string
|
|
30
|
+
id: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface BaseCommentIndexModel extends BaseModel {
|
|
34
|
+
commentsIndex?: number
|
|
35
|
+
|
|
36
|
+
allowComment: boolean
|
|
37
|
+
}
|
|
38
|
+
export interface TextBaseModel extends BaseCommentIndexModel {
|
|
39
|
+
title: string
|
|
40
|
+
text: string
|
|
41
|
+
images?: Image[]
|
|
42
|
+
modified: string | null
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseModel } from './base'
|
|
2
|
+
import { PostModel } from './post'
|
|
3
|
+
|
|
4
|
+
export enum CategoryType {
|
|
5
|
+
Category,
|
|
6
|
+
Tag,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CategoryModel extends BaseModel {
|
|
10
|
+
type: CategoryType
|
|
11
|
+
count: number
|
|
12
|
+
slug: string
|
|
13
|
+
name: string
|
|
14
|
+
}
|
|
15
|
+
export type CategoryWithChildrenModel = CategoryModel & {
|
|
16
|
+
children: Pick<PostModel, 'id' | 'title' | 'slug' | 'modified' | 'created'>[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CategoryEntries = {
|
|
20
|
+
entries: Record<string, CategoryWithChildrenModel>
|
|
21
|
+
}
|
|
22
|
+
export interface TagModel {
|
|
23
|
+
count: number
|
|
24
|
+
name: string
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseModel } from './base'
|
|
2
|
+
import { CategoryModel } from './category'
|
|
3
|
+
|
|
4
|
+
export enum RefType {
|
|
5
|
+
Page = 'Page',
|
|
6
|
+
Post = 'Post',
|
|
7
|
+
Note = 'Note',
|
|
8
|
+
}
|
|
9
|
+
export interface CommentModel extends BaseModel {
|
|
10
|
+
refType: RefType
|
|
11
|
+
state: number
|
|
12
|
+
comments_index: number
|
|
13
|
+
author: string
|
|
14
|
+
text: string
|
|
15
|
+
mail?: string
|
|
16
|
+
url?: string
|
|
17
|
+
ip?: string
|
|
18
|
+
agent?: string
|
|
19
|
+
key: string
|
|
20
|
+
|
|
21
|
+
avatar: string
|
|
22
|
+
parent?: CommentModel | string
|
|
23
|
+
children: CommentModel[]
|
|
24
|
+
}
|
|
25
|
+
export interface CommentRef {
|
|
26
|
+
id: string
|
|
27
|
+
categoryId?: string
|
|
28
|
+
slug: string
|
|
29
|
+
title: string
|
|
30
|
+
category?: CategoryModel
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export enum CommentState {
|
|
34
|
+
Unread,
|
|
35
|
+
Read,
|
|
36
|
+
Junk,
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './aggregate'
|
|
2
|
+
export * from './base'
|
|
3
|
+
export * from './category'
|
|
4
|
+
export * from './comment'
|
|
5
|
+
export * from './link'
|
|
6
|
+
export * from './note'
|
|
7
|
+
export * from './page'
|
|
8
|
+
export * from './post'
|
|
9
|
+
export * from './project'
|
|
10
|
+
export * from './recently'
|
|
11
|
+
export * from './say'
|
|
12
|
+
export * from './setting'
|
|
13
|
+
export * from './snippet'
|
|
14
|
+
export * from './user'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseModel } from './base'
|
|
2
|
+
|
|
3
|
+
export enum LinkType {
|
|
4
|
+
Friend,
|
|
5
|
+
Collection,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export enum LinkState {
|
|
9
|
+
Pass,
|
|
10
|
+
Audit,
|
|
11
|
+
Outdate,
|
|
12
|
+
Banned,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface LinkModel extends BaseModel {
|
|
16
|
+
name: string
|
|
17
|
+
url: string
|
|
18
|
+
avatar: string
|
|
19
|
+
description?: string
|
|
20
|
+
type: LinkType
|
|
21
|
+
state: LinkState
|
|
22
|
+
hide: boolean
|
|
23
|
+
}
|