mobx-lark 2.4.3 → 2.5.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.
@@ -1,8 +1,9 @@
1
1
  import { Filter, ListModel, Stream, toggle } from 'mobx-restful';
2
+ import { buildURLData } from 'web-utility';
2
3
 
3
4
  import { LarkData } from '../../type';
4
5
  import { createPageStream } from '../base';
5
- import { Wiki, WikiNode } from './type';
6
+ import { Wiki, WikiNode, WikiTask } from './type';
6
7
 
7
8
  export * from './type';
8
9
 
@@ -12,14 +13,13 @@ export abstract class WikiModel extends Stream<Wiki>(ListModel) {
12
13
  /**
13
14
  * @see {@link https://open.feishu.cn/document/server-docs/docs/wiki-v2/space/list}
14
15
  */
15
- async *openStream() {
16
- for await (const item of createPageStream<Wiki>(
16
+ openStream() {
17
+ return createPageStream<Wiki>(
17
18
  this.client,
18
19
  this.baseURI,
19
20
  total => (this.totalCount = total),
20
21
  { page_size: 50 }
21
- ))
22
- yield item;
22
+ );
23
23
  }
24
24
  }
25
25
 
@@ -82,4 +82,43 @@ export abstract class WikiNodeModel extends Stream<WikiNode>(ListModel) {
82
82
  }
83
83
  onCount?.(totalCount);
84
84
  }
85
+
86
+ /**
87
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/wiki-v2/task/move_docs_to_wiki}
88
+ */
89
+ @toggle('uploading')
90
+ async moveDocument(
91
+ document: Pick<WikiNode, 'obj_type' | 'obj_token'>,
92
+ parent_wiki_token = '',
93
+ apply = true
94
+ ) {
95
+ type WikiTaskMeta = { wiki_token: string } | { task_id: string } | { applied: boolean };
96
+
97
+ const { body } = await this.client.post<LarkData<WikiTaskMeta>>(
98
+ `${this.baseURI}/move_docs_to_wiki`,
99
+ { ...document, parent_wiki_token, apply }
100
+ );
101
+ if ('applied' in body!.data!) return;
102
+
103
+ if ('wiki_token' in body!.data!) return this.getOne(body!.data!.wiki_token);
104
+
105
+ const { move_result } = await this.getOneTask(body!.data!.task_id);
106
+
107
+ const [{ status, status_msg, node }] = move_result;
108
+
109
+ if (status < 0) throw new URIError(status_msg);
110
+
111
+ return node;
112
+ }
113
+
114
+ /**
115
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/wiki-v2/task/get}
116
+ */
117
+ @toggle('downloading')
118
+ async getOneTask(taskId: string, task_type = 'move') {
119
+ const { body } = await this.client.get<LarkData<{ task: WikiTask }>>(
120
+ `wiki/v2/tasks/${taskId}?${buildURLData({ task_type })}`
121
+ );
122
+ return body!.data!.task;
123
+ }
85
124
  }
@@ -24,3 +24,8 @@ export interface WikiNode
24
24
  */
25
25
  title_path?: string;
26
26
  }
27
+
28
+ export interface WikiTask {
29
+ task_id: string;
30
+ move_result: { status: number; status_msg: string; node: WikiNode }[];
31
+ }