@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.
Files changed (120) hide show
  1. package/build/index.cjs.js +18 -0
  2. package/build/index.cjs.js.map +1 -1
  3. package/build/index.cjs.min.js.map +1 -1
  4. package/build/index.d.ts +42 -18
  5. package/build/index.esm.js +18 -0
  6. package/build/index.esm.js.map +1 -1
  7. package/build/index.esm.min.js.map +1 -1
  8. package/build/index.umd.js +18 -0
  9. package/build/index.umd.js.map +1 -1
  10. package/build/index.umd.min.js.map +1 -1
  11. package/esm/controllers/aggregate.d.ts +5 -0
  12. package/esm/controllers/aggregate.js.map +1 -1
  13. package/esm/controllers/category.d.ts +5 -0
  14. package/esm/controllers/category.js.map +1 -1
  15. package/esm/controllers/comment.d.ts +5 -0
  16. package/esm/controllers/comment.js.map +1 -1
  17. package/esm/controllers/link.d.ts +6 -0
  18. package/esm/controllers/link.js.map +1 -1
  19. package/esm/controllers/note.d.ts +5 -0
  20. package/esm/controllers/note.js.map +1 -1
  21. package/esm/controllers/page.d.ts +5 -0
  22. package/esm/controllers/page.js.map +1 -1
  23. package/esm/controllers/post.d.ts +5 -0
  24. package/esm/controllers/post.js.map +1 -1
  25. package/esm/controllers/project.d.ts +5 -0
  26. package/esm/controllers/project.js.map +1 -1
  27. package/esm/controllers/recently.d.ts +6 -0
  28. package/esm/controllers/recently.js.map +1 -1
  29. package/esm/controllers/say.d.ts +5 -0
  30. package/esm/controllers/say.js.map +1 -1
  31. package/esm/controllers/search.d.ts +7 -2
  32. package/esm/controllers/search.js.map +1 -1
  33. package/esm/controllers/snippet.d.ts +5 -0
  34. package/esm/controllers/snippet.js.map +1 -1
  35. package/esm/controllers/user.d.ts +6 -0
  36. package/esm/controllers/user.js.map +1 -1
  37. package/esm/core/client.d.ts +0 -19
  38. package/esm/core/client.js +19 -1
  39. package/esm/core/client.js.map +1 -1
  40. package/lib/controllers/aggregate.d.ts +5 -0
  41. package/lib/controllers/aggregate.js.map +1 -1
  42. package/lib/controllers/category.d.ts +5 -0
  43. package/lib/controllers/category.js.map +1 -1
  44. package/lib/controllers/comment.d.ts +5 -0
  45. package/lib/controllers/comment.js.map +1 -1
  46. package/lib/controllers/link.d.ts +6 -0
  47. package/lib/controllers/link.js.map +1 -1
  48. package/lib/controllers/note.d.ts +5 -0
  49. package/lib/controllers/note.js.map +1 -1
  50. package/lib/controllers/page.d.ts +5 -0
  51. package/lib/controllers/page.js.map +1 -1
  52. package/lib/controllers/post.d.ts +5 -0
  53. package/lib/controllers/post.js.map +1 -1
  54. package/lib/controllers/project.d.ts +5 -0
  55. package/lib/controllers/project.js.map +1 -1
  56. package/lib/controllers/recently.d.ts +6 -0
  57. package/lib/controllers/recently.js.map +1 -1
  58. package/lib/controllers/say.d.ts +5 -0
  59. package/lib/controllers/say.js.map +1 -1
  60. package/lib/controllers/search.d.ts +7 -2
  61. package/lib/controllers/search.js.map +1 -1
  62. package/lib/controllers/snippet.d.ts +5 -0
  63. package/lib/controllers/snippet.js.map +1 -1
  64. package/lib/controllers/user.d.ts +6 -0
  65. package/lib/controllers/user.js.map +1 -1
  66. package/lib/core/client.d.ts +0 -19
  67. package/lib/core/client.js +18 -0
  68. package/lib/core/client.js.map +1 -1
  69. package/package.json +11 -4
  70. package/src/adaptors/axios.ts +36 -0
  71. package/src/adaptors/umi-request.ts +30 -0
  72. package/src/controllers/aggregate.ts +65 -0
  73. package/src/controllers/base.ts +32 -0
  74. package/src/controllers/category.ts +107 -0
  75. package/src/controllers/comment.ts +64 -0
  76. package/src/controllers/index.ts +66 -0
  77. package/src/controllers/link.ts +21 -0
  78. package/src/controllers/note.ts +92 -0
  79. package/src/controllers/page.ts +59 -0
  80. package/src/controllers/post.ts +87 -0
  81. package/src/controllers/project.ts +20 -0
  82. package/src/controllers/recently.ts +48 -0
  83. package/src/controllers/say.ts +35 -0
  84. package/src/controllers/search.ts +101 -0
  85. package/src/controllers/snippet.ts +31 -0
  86. package/src/controllers/user.ts +46 -0
  87. package/src/core/attach-request.ts +43 -0
  88. package/src/core/client.ts +249 -0
  89. package/src/core/error.ts +10 -0
  90. package/src/core/index.ts +2 -0
  91. package/src/dtos/comment.ts +9 -0
  92. package/src/index.ts +12 -0
  93. package/src/interfaces/adapter.ts +30 -0
  94. package/src/interfaces/client.ts +6 -0
  95. package/src/interfaces/controller.ts +5 -0
  96. package/src/interfaces/instance.ts +8 -0
  97. package/src/interfaces/options.ts +1 -0
  98. package/src/interfaces/params.ts +4 -0
  99. package/src/interfaces/request.ts +57 -0
  100. package/src/models/aggregate.ts +71 -0
  101. package/src/models/base.ts +43 -0
  102. package/src/models/category.ts +25 -0
  103. package/src/models/comment.ts +37 -0
  104. package/src/models/index.ts +14 -0
  105. package/src/models/link.ts +23 -0
  106. package/src/models/note.ts +37 -0
  107. package/src/models/page.ts +20 -0
  108. package/src/models/post.ts +16 -0
  109. package/src/models/project.ts +12 -0
  110. package/src/models/recently.ts +7 -0
  111. package/src/models/say.ts +7 -0
  112. package/src/models/setting.ts +68 -0
  113. package/src/models/snippet.ts +18 -0
  114. package/src/models/user.ts +27 -0
  115. package/src/tsconfig.build.json +6 -0
  116. package/src/tsconfig.cjs.json +7 -0
  117. package/src/tsconfig.json +12 -0
  118. package/src/types/helper.d.ts +3 -0
  119. package/src/utils/auto-bind.ts +48 -0
  120. package/src/utils/index.ts +53 -0
@@ -0,0 +1,37 @@
1
+ import { TextBaseModel } from './base'
2
+
3
+ export interface NoteModel extends TextBaseModel {
4
+ hide: boolean
5
+ count: {
6
+ read: number
7
+ like: number
8
+ }
9
+
10
+ mood?: string
11
+ weather?: string
12
+ hasMemory?: boolean
13
+
14
+ secret?: Date
15
+ password?: string | null
16
+ nid: number
17
+ music?: NoteMusicRecord[]
18
+ location?: string
19
+
20
+ coordinates?: Coordinate
21
+ }
22
+
23
+ export interface NoteMusicRecord {
24
+ type: string
25
+ id: string
26
+ }
27
+
28
+ export interface Coordinate {
29
+ latitude: number
30
+ longitude: number
31
+ }
32
+
33
+ export interface NoteWrappedPayload {
34
+ data: NoteModel
35
+ next?: Partial<NoteModel>
36
+ prev?: Partial<NoteModel>
37
+ }
@@ -0,0 +1,20 @@
1
+ import { TextBaseModel } from './base'
2
+
3
+ export enum EnumPageType {
4
+ 'md' = 'md',
5
+ 'html' = 'html',
6
+ 'frame' = 'frame',
7
+ }
8
+ export interface PageModel extends TextBaseModel {
9
+ created: string
10
+
11
+ slug: string
12
+
13
+ subtitle?: string
14
+
15
+ order?: number
16
+
17
+ type?: EnumPageType
18
+
19
+ options?: object
20
+ }
@@ -0,0 +1,16 @@
1
+ import { Count, Image, TextBaseModel } from './base'
2
+ import { CategoryModel } from './category'
3
+
4
+ export interface PostModel extends TextBaseModel {
5
+ summary?: string
6
+ hide: boolean
7
+ copyright: boolean
8
+ tags: string[]
9
+ count: Count
10
+ text: string
11
+ title: string
12
+ slug: string
13
+ categoryId: string
14
+ images: Image[]
15
+ category: CategoryModel
16
+ }
@@ -0,0 +1,12 @@
1
+ import { BaseModel } from './base'
2
+
3
+ export interface ProjectModel extends BaseModel {
4
+ name: string
5
+ previewUrl?: string
6
+ docUrl?: string
7
+ projectUrl?: string
8
+ images?: string[]
9
+ description: string
10
+ avatar?: string
11
+ text: string
12
+ }
@@ -0,0 +1,7 @@
1
+ import { BaseModel } from './base'
2
+
3
+ export interface RecentlyModel extends BaseModel {
4
+ content: string
5
+ project?: string
6
+ language?: string
7
+ }
@@ -0,0 +1,7 @@
1
+ import { BaseModel } from './base'
2
+
3
+ export interface SayModel extends BaseModel {
4
+ text: string
5
+ source?: string
6
+ author?: string
7
+ }
@@ -0,0 +1,68 @@
1
+ export declare class SeoOptionModel {
2
+ title: string
3
+ description: string
4
+ icon?: string
5
+ keywords?: string[]
6
+ }
7
+ export declare class UrlOptionModel {
8
+ webUrl: string
9
+ adminUrl: string
10
+ serverUrl: string
11
+ wsUrl: string
12
+ }
13
+ declare class MailOptionModel {
14
+ port: number
15
+ host: string
16
+ }
17
+ export declare class MailOptionsModel {
18
+ enable: boolean
19
+ user: string
20
+ pass: string
21
+ options?: MailOptionModel
22
+ }
23
+ export declare class CommentOptionsModel {
24
+ antiSpam: boolean
25
+ spamKeywords?: string[]
26
+ blockIps?: string[]
27
+ disableNoChinese?: boolean
28
+ }
29
+ export declare class BackupOptionsModel {
30
+ enable: boolean
31
+ secretId?: string
32
+ secretKey?: string
33
+ bucket?: string
34
+ region: string
35
+ }
36
+ export declare class BaiduSearchOptionsModel {
37
+ enable: boolean
38
+ token?: string
39
+ }
40
+ export declare class AlgoliaSearchOptionsModel {
41
+ enable: boolean
42
+ apiKey?: string
43
+ appId?: string
44
+ indexName?: string
45
+ }
46
+
47
+ export declare class AdminExtraModel {
48
+ background?: string
49
+
50
+ gaodemapKey?: string
51
+ title?: string
52
+ /**
53
+ * 是否开启后台反代访问
54
+ */
55
+ enableAdminProxy?: boolean
56
+ }
57
+
58
+ export interface IConfig {
59
+ seo: SeoOptionModel
60
+ url: UrlOptionModel
61
+ mailOptions: MailOptionsModel
62
+ commentOptions: CommentOptionsModel
63
+ backupOptions: BackupOptionsModel
64
+ baiduSearchOptions: BaiduSearchOptionsModel
65
+ algoliaSearchOptions: AlgoliaSearchOptionsModel
66
+ adminExtra: AdminExtraModel
67
+ }
68
+ export declare type IConfigKeys = keyof IConfig
@@ -0,0 +1,18 @@
1
+ import { BaseModel } from './base'
2
+ export enum SnippetType {
3
+ JSON = 'json',
4
+ // Function = 'function',
5
+ Text = 'text',
6
+ YAML = 'yaml',
7
+ }
8
+ export interface SnippetModel<T = unknown> extends BaseModel {
9
+ type: SnippetType
10
+ private: boolean
11
+ raw: string
12
+ name: string
13
+ reference: string
14
+ comment?: string
15
+ metatype?: string
16
+
17
+ data: T
18
+ }
@@ -0,0 +1,27 @@
1
+ import { BaseModel } from './base'
2
+
3
+ export interface UserModel extends BaseModel {
4
+ introduce: string
5
+ mail: string
6
+ url: string
7
+ name: string
8
+ socialIds: Record<string, string>
9
+ username: string
10
+ modified: string
11
+ v: number
12
+ lastLoginTime: string
13
+ lastLoginIp?: string
14
+ avatar: string
15
+ postID: string
16
+ }
17
+
18
+ export type TLogin = {
19
+ token: string
20
+ expiresIn: number
21
+ // 登陆足迹
22
+ lastLoginTime: null | string
23
+ lastLoginIp?: null | string
24
+ } & Pick<
25
+ UserModel,
26
+ 'name' | 'username' | 'created' | 'url' | 'mail' | 'avatar' | 'id'
27
+ >
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": [
4
+ "__tests__/**/*.ts"
5
+ ]
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "module": "CommonJS",
5
+ "outDir": "../lib"
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "../esm",
6
+ "baseUrl": ".",
7
+ "jsx": "react"
8
+ },
9
+ "include": [
10
+ "./**/*.ts"
11
+ ]
12
+ }
@@ -0,0 +1,3 @@
1
+ export type Class<T> = new (...args: any[]) => T
2
+
3
+ export type SelectFields<T extends string> = `${'+' | '-' | ''}${T}`[]
@@ -0,0 +1,48 @@
1
+ // @ts-nocheck
2
+ // @copy: https://github.com/sindresorhus/auto-bind/blob/main/index.js
3
+
4
+ // Gets all non-builtin properties up the prototype chain.
5
+ const getAllProperties = (object) => {
6
+ const properties = new Set()
7
+
8
+ do {
9
+ for (const key of Reflect.ownKeys(object)) {
10
+ properties.add([object, key])
11
+ }
12
+ } while (
13
+ (object = Reflect.getPrototypeOf(object)) &&
14
+ object !== Object.prototype
15
+ )
16
+
17
+ return properties
18
+ }
19
+
20
+ export function autoBind(self, { include, exclude } = {}) {
21
+ const filter = (key) => {
22
+ const match = (pattern) =>
23
+ typeof pattern === 'string' ? key === pattern : pattern.test(key)
24
+
25
+ if (include) {
26
+ return include.some(match)
27
+ }
28
+
29
+ if (exclude) {
30
+ return !exclude.some(match)
31
+ }
32
+
33
+ return true
34
+ }
35
+
36
+ for (const [object, key] of getAllProperties(self.constructor.prototype)) {
37
+ if (key === 'constructor' || !filter(key)) {
38
+ continue
39
+ }
40
+
41
+ const descriptor = Reflect.getOwnPropertyDescriptor(object, key)
42
+ if (descriptor && typeof descriptor.value === 'function') {
43
+ self[key] = self[key].bind(self)
44
+ }
45
+ }
46
+
47
+ return self
48
+ }
@@ -0,0 +1,53 @@
1
+ import { SortOrder } from '~/interfaces/options'
2
+
3
+ export const isPlainObject = (obj: any) =>
4
+ isObject(obj) &&
5
+ Object.prototype.toString.call(obj) === '[object Object]' &&
6
+ Object.getPrototypeOf(obj) === Object.prototype
7
+
8
+ export const sortOrderToNumber = (order: SortOrder) => {
9
+ return (
10
+ {
11
+ asc: 1,
12
+ desc: -1,
13
+ }[order] || 1
14
+ )
15
+ }
16
+ const isObject = (obj: any) => obj && typeof obj === 'object'
17
+ export const destructureData = (payload: any) => {
18
+ if (typeof payload !== 'object') {
19
+ return payload
20
+ }
21
+ if (payload === null) {
22
+ return payload
23
+ }
24
+
25
+ const data = payload.data
26
+
27
+ const dataIsPlainObject = isPlainObject(data)
28
+
29
+ if (dataIsPlainObject && Object.keys(payload).length === 1) {
30
+ const d = Object.assign({}, data)
31
+ // attach raw onto new data
32
+ attachRawFromOneToAnthor(payload, d)
33
+ return d
34
+ }
35
+
36
+ return payload
37
+ }
38
+
39
+ export const attachRawFromOneToAnthor = (from: any, to: any) => {
40
+ if (!from || !isObject(to)) {
41
+ return
42
+ }
43
+ from.$raw &&
44
+ Object.defineProperty(to, '$raw', {
45
+ value: { ...from.$raw },
46
+ enumerable: false,
47
+ })
48
+ from.$request &&
49
+ Object.defineProperty(to, '$request', {
50
+ value: { ...from.$request },
51
+ enumerable: false,
52
+ })
53
+ }