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,15 +1,106 @@
1
- import { BaseListModel } from 'mobx-restful';
2
- import { Block, Document, IframeBlock, OrderedBlock, QuoteContainerBlock, TextBlock } from './type';
1
+ import { BaseListModel, IDType, ListModel, NewData } from 'mobx-restful';
2
+ import { UserIdType } from '../User/type';
3
+ import { Block, Document, DocumentBlockUpdateResult, PageBlock } from './type';
3
4
  export * from './type';
4
5
  export * from './component';
5
6
  export type FileURLResolver = (token: string) => string | Promise<string>;
6
7
  export declare abstract class DocumentModel extends BaseListModel<Document> {
7
- #private;
8
8
  domain: string;
9
9
  baseURI: string;
10
10
  constructor(domain: string);
11
+ /**
12
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/get}
13
+ */
14
+ getOne(id: IDType): Promise<Document>;
15
+ /**
16
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/create}
17
+ */
18
+ updateOne(data: Partial<NewData<Document>>, id?: IDType): Promise<Document>;
19
+ /**
20
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/raw_content}
21
+ * @see {@link https://open.feishu.cn/document/docs/docs-v1/get}
22
+ */
23
+ getOneContent(doc_token: string, content_type?: 'text' | 'markdown', lang?: 'zh' | 'en' | 'ja'): Promise<string>;
24
+ getOneBlocks(id: string, resolveFileURL?: FileURLResolver): Promise<Block<any, any, any>[]>;
25
+ updateOneBlocks(id: string, markUpDown: string, user_id_type?: UserIdType): Promise<DocumentBlockUpdateResult & {
26
+ children: Block<any, any, any>[];
27
+ block_id_relations: Record<`${"temporary_" | ""}block_id`, string>[];
28
+ }>;
29
+ }
30
+ declare const DocumentBlockModel_base: (abstract new (...args: any[]) => {
31
+ stream?: AsyncGenerator<Block<any, any, any>, void, any> | undefined;
32
+ openStream(filter: Partial<NewData<Block<any, any, any>>>): AsyncGenerator<Block<any, any, any>, void, any>;
33
+ clearList(): void;
34
+ clear(): void;
35
+ restoreList({ filter, pageIndex, pageSize, allItems, totalCount }?: Partial<Pick<ListModel<Block<any, any, any>, Partial<NewData<Block<any, any, any>>>>, "filter" | "pageIndex" | "pageSize" | "allItems" | "totalCount">> | undefined): Promise<void>;
36
+ loadStream(filter: Partial<NewData<Block<any, any, any>>>, newCount: number): Promise<Block<any, any, any>[]>;
37
+ loadPage(pageIndex: number, pageSize: number, filter: Partial<NewData<Block<any, any, any>>>): Promise<{
38
+ pageData: Block<any, any, any>[];
39
+ totalCount: number;
40
+ }>;
41
+ pageIndex: number;
42
+ pageSize: number;
43
+ filter: Partial<NewData<Block<any, any, any>>>;
44
+ totalCount: number;
45
+ pageList: Block<any, any, any>[][];
46
+ readonly currentPage: Block<any, any, any>[];
47
+ readonly pageCount: number;
48
+ readonly allItems: Block<any, any, any>[];
49
+ readonly noMore: boolean;
50
+ statistic: Partial<Record<string, Record<string, number>>>;
51
+ turnTo(pageIndex: number, pageSize?: number): ListModel<Block<any, any, any>, Partial<NewData<Block<any, any, any>>>>;
52
+ loadNewPage(pageIndex: number, pageSize: number, filter: Partial<NewData<Block<any, any, any>>>): Promise<{
53
+ pageData: Block<any, any, any>[];
54
+ totalCount: number;
55
+ }>;
56
+ getList(filter?: Partial<NewData<Block<any, any, any>>> | undefined, pageIndex?: number, pageSize?: number): Promise<Block<any, any, any>[]>;
57
+ refreshList(): Promise<Block<any, any, any>[]>;
58
+ getAllInStream(filter?: Partial<NewData<Block<any, any, any>>> | undefined, pageSize?: number): AsyncGenerator<Block<any, any, any>, void, unknown>;
59
+ getAll(filter?: Partial<NewData<Block<any, any, any>>> | undefined, pageSize?: number): Promise<Block<any, any, any>[]>;
60
+ countAll(keys: string[], filter?: Partial<NewData<Block<any, any, any>>> | undefined, pageSize?: number): Promise<Partial<Record<string, Record<string, number>>>>;
61
+ indexOf(id: IDType): number;
62
+ changeOne(data: Partial<Block<any, any, any>>, id: IDType, patch?: boolean): void;
63
+ updateOne(data: Partial<NewData<Block<any, any, any>>>, id?: IDType): Promise<Block<any, any, any>>;
64
+ removeOne(id: IDType): Promise<void>;
65
+ deleteOne(id: IDType): Promise<void>;
66
+ client: import("mobx-restful").RESTClient;
67
+ baseURI: string;
68
+ indexKey: any;
69
+ currentOne: Block<any, any, any>;
70
+ clearCurrent(): void;
71
+ getOne(id: IDType): Promise<Block<any, any, any>>;
72
+ downloading: number;
73
+ uploading: number;
74
+ [Symbol.asyncIterator]: (filter?: Partial<NewData<Block<any, any, any>>> | undefined, pageSize?: number) => AsyncGenerator<Block<any, any, any>, void, unknown>;
75
+ }) & import("web-utility").AbstractClass<ListModel<Block<any, any, any>, Partial<NewData<Block<any, any, any>>>>>;
76
+ export declare abstract class DocumentBlockModel extends DocumentBlockModel_base {
77
+ #private;
78
+ domain: string;
79
+ documentId: string;
80
+ constructor(domain: string, documentId: string);
81
+ openStream(): AsyncGenerator<Block<any, any, any>, void, unknown>;
11
82
  /**
12
83
  * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/list}
13
84
  */
14
- getOneBlocks(id: string, resolveFileURL?: FileURLResolver): Promise<(OrderedBlock | QuoteContainerBlock | IframeBlock | TextBlock | Block<any, any, any>)[]>;
85
+ getRenderableAll(resolveFileURL?: FileURLResolver): Promise<Block<any, any, any>[]>;
86
+ /**
87
+ * @see {@link https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document/convert}
88
+ */
89
+ convertFrom(markUpDown: string, user_id_type?: UserIdType): Promise<{
90
+ first_level_block_ids: string[];
91
+ blocks: Block<any, any>[];
92
+ block_id_to_image_urls: Record<"block_id" | "image_url", string>[];
93
+ }>;
94
+ getRoot(): Promise<PageBlock | undefined>;
95
+ /**
96
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document-block/batch_delete}
97
+ */
98
+ removeAll(): Promise<void>;
99
+ /**
100
+ * @see {@link https://open.feishu.cn/document/docs/docs/document-block/create-2}
101
+ */
102
+ insert(markUpDown: string, index?: number, rootBlockId?: string, user_id_type?: UserIdType): Promise<DocumentBlockUpdateResult & {
103
+ children: Block<any, any, any>[];
104
+ block_id_relations: Record<`${"temporary_" | ""}block_id`, string>[];
105
+ }>;
15
106
  }
@@ -11,3 +11,7 @@ export interface Document extends Record<'document_id' | 'title', string> {
11
11
  };
12
12
  display_setting: Record<`show_${'authors' | `${'comment' | 'like'}_count` | 'create_time' | 'pv' | 'uv'}`, boolean>;
13
13
  }
14
+ export interface DocumentBlockUpdateResult {
15
+ document_revision_id: number;
16
+ client_token: string;
17
+ }
@@ -1,5 +1,5 @@
1
1
  import { Filter, ListModel } from 'mobx-restful';
2
- import { Wiki, WikiNode } from './type';
2
+ import { Wiki, WikiNode, WikiTask } from './type';
3
3
  export * from './type';
4
4
  declare const WikiModel_base: (abstract new (...args: any[]) => {
5
5
  stream?: AsyncGenerator<Wiki, void, any> | undefined;
@@ -114,4 +114,12 @@ export declare abstract class WikiNodeModel extends WikiNodeModel_base {
114
114
  * @see {@link https://open.feishu.cn/document/server-docs/docs/wiki-v2/space-node/list}
115
115
  */
116
116
  traverseTree(parentNode?: WikiNode, onCount?: (total: number) => any): AsyncGenerator<WikiNode>;
117
+ /**
118
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/wiki-v2/task/move_docs_to_wiki}
119
+ */
120
+ moveDocument(document: Pick<WikiNode, 'obj_type' | 'obj_token'>, parent_wiki_token?: string, apply?: boolean): Promise<WikiNode | undefined>;
121
+ /**
122
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/wiki-v2/task/get}
123
+ */
124
+ getOneTask(taskId: string, task_type?: string): Promise<WikiTask>;
117
125
  }
@@ -12,3 +12,11 @@ export interface WikiNode extends Record<'title' | 'creator' | 'owner' | `${'' |
12
12
  */
13
13
  title_path?: string;
14
14
  }
15
+ export interface WikiTask {
16
+ task_id: string;
17
+ move_result: {
18
+ status: number;
19
+ status_msg: string;
20
+ node: WikiNode;
21
+ }[];
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-lark",
3
- "version": "2.4.3",
3
+ "version": "2.5.0",
4
4
  "license": "LGPL-3.0",
5
5
  "author": "shiy2008@gmail.com",
6
6
  "description": "Unofficial TypeScript SDK for FeiShu/Lark API, which is based on MobX-RESTful.",
@@ -30,7 +30,7 @@
30
30
  "koajax": "^3.1.2",
31
31
  "lodash.memoize": "^4.1.2",
32
32
  "mobx": "^6.15.0",
33
- "mobx-restful": "^2.1.3",
33
+ "mobx-restful": "^2.1.4",
34
34
  "regenerator-runtime": "^0.14.1",
35
35
  "web-utility": "^4.6.2"
36
36
  },
@@ -42,13 +42,13 @@
42
42
  "@parcel/transformer-typescript-tsc": "~2.16.0",
43
43
  "@types/fs-extra": "^11.0.4",
44
44
  "@types/lodash.memoize": "^4.1.9",
45
- "@types/node": "^22.18.10",
45
+ "@types/node": "^22.18.12",
46
46
  "@types/react-dom": "^19.2.2",
47
47
  "@types/turndown": "^5.0.5",
48
48
  "dotenv": "^17.2.3",
49
49
  "fs-extra": "^11.3.2",
50
50
  "husky": "^9.1.7",
51
- "lint-staged": "^16.2.4",
51
+ "lint-staged": "^16.2.5",
52
52
  "parcel": "~2.16.0",
53
53
  "prettier": "^3.6.2",
54
54
  "react": "^19.2.0",
package/src/Lark.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Context, HTTPClient, makeFormData } from 'koajax';
2
2
  import { buildURLData, cache, sleep } from 'web-utility';
3
3
 
4
- import { WikiNodeModel } from './module';
4
+ import { DocumentModel, WikiNodeModel } from './module';
5
5
  import {
6
6
  isLarkError,
7
7
  JSTicket,
@@ -209,22 +209,19 @@ export class LarkApp implements LarkAppOption {
209
209
  static documentPathPattern = /(wiki|docx)\/(\w+)/;
210
210
 
211
211
  /**
212
- * @see {@link https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/docs-v1/content/get}
212
+ * @see {@link DocumentModel#getOneContent}
213
213
  */
214
214
  async downloadMarkdown(URI: string) {
215
215
  await this.getAccessToken();
216
216
 
217
217
  const [, type, id] = URI.match(LarkApp.documentPathPattern) || [];
218
218
 
219
- const doc_token = type === 'wiki' ? await this.wiki2docx(id) : id;
219
+ const doc_token = type === 'wiki' ? await this.wiki2docx(id) : id,
220
+ { client } = this;
220
221
 
221
- const { body } = await this.client.get<LarkData<{ content: string }>>(
222
- `docs/v1/content?${new URLSearchParams({
223
- doc_type: 'docx',
224
- doc_token,
225
- content_type: 'markdown'
226
- })}`
227
- );
228
- return body!.data!.content;
222
+ class InternalDocumentModel extends DocumentModel {
223
+ client = client;
224
+ }
225
+ return new InternalDocumentModel('').getOneContent(doc_token, 'markdown');
229
226
  }
230
227
  }
@@ -275,13 +275,12 @@ export function BiTable() {
275
275
  /**
276
276
  * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table/list}
277
277
  */
278
- async *openStream() {
279
- for await (const item of createPageStream<BITable>(
278
+ openStream() {
279
+ return createPageStream<BITable>(
280
280
  this.client,
281
281
  this.baseURI,
282
282
  total => (this.totalCount = total)
283
- ))
284
- yield item;
283
+ );
285
284
  }
286
285
  }
287
286
  return BiTableModel;
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { uniqueID } from 'web-utility';
2
+ import { clone, uniqueID } from 'web-utility';
3
3
 
4
4
  import { Block, BlockType } from '../type';
5
5
  import { ListBlockComponent, TextBlockComponent } from './Text';
@@ -55,7 +55,7 @@ export const blockComponentMap: Partial<Record<BlockType, FC<any>>> = {
55
55
  export const blockMap: Record<string, Block<any, any, any>> = {};
56
56
 
57
57
  export function registerBlocks<T extends Block<any, any, any>>(blocks: T[]) {
58
- blocks = globalThis.structuredClone?.(blocks) || JSON.parse(JSON.stringify(blocks));
58
+ blocks = clone(blocks);
59
59
 
60
60
  let root: T | undefined;
61
61
 
@@ -1,23 +1,25 @@
1
1
  import { HTTPError } from 'koajax';
2
2
  import memoize from 'lodash.memoize';
3
- import { BaseListModel } from 'mobx-restful';
4
- import { formatDate, uniqueID } from 'web-utility';
3
+ import { BaseListModel, IDType, ListModel, NewData, Stream, toggle } from 'mobx-restful';
4
+ import { buildURLData, formatDate, uniqueID } from 'web-utility';
5
5
 
6
6
  import { isLarkError, LarkData } from '../../type';
7
7
  import { createPageStream } from '../base';
8
8
  import { TaskModel } from '../Task';
9
- import { User } from '../User/type';
9
+ import { User, UserIdType } from '../User/type';
10
10
  import { WikiNode, WikiNodeModel } from '../Wiki';
11
11
  import {
12
12
  BiTableBlock,
13
13
  Block,
14
14
  BlockType,
15
15
  Document,
16
+ DocumentBlockUpdateResult,
16
17
  FileBlock,
17
18
  IframeBlock,
18
19
  IframeComponentType,
19
20
  ImageBlock,
20
21
  OrderedBlock,
22
+ PageBlock,
21
23
  QuoteContainerBlock,
22
24
  SheetBlock,
23
25
  SubPageList,
@@ -40,6 +42,91 @@ export abstract class DocumentModel extends BaseListModel<Document> {
40
42
  super();
41
43
  }
42
44
 
45
+ /**
46
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/get}
47
+ */
48
+ @toggle('downloading')
49
+ async getOne(id: IDType) {
50
+ const { body } = await this.client.get<LarkData<{ document: Document }>>(
51
+ `${this.baseURI}/${id}`
52
+ );
53
+ return (this.currentOne = body!.data!.document);
54
+ }
55
+
56
+ /**
57
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/create}
58
+ */
59
+ @toggle('uploading')
60
+ async updateOne(data: Partial<NewData<Document>>, id?: IDType) {
61
+ const { body } = await this.client.post<LarkData<{ document: Document }>>(
62
+ this.baseURI,
63
+ data
64
+ );
65
+ return (this.currentOne = body!.data!.document);
66
+ }
67
+
68
+ /**
69
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/raw_content}
70
+ * @see {@link https://open.feishu.cn/document/docs/docs-v1/get}
71
+ */
72
+ @toggle('downloading')
73
+ async getOneContent(
74
+ doc_token: string,
75
+ content_type: 'text' | 'markdown' = 'markdown',
76
+ lang: 'zh' | 'en' | 'ja' = 'zh'
77
+ ) {
78
+ const { body } = await (content_type === 'text'
79
+ ? this.client.get<LarkData<{ content: string }>>(
80
+ `${this.baseURI}/${doc_token}/raw_content?${buildURLData({ lang: ['zh', 'en', 'ja'].indexOf(lang) })}`
81
+ )
82
+ : this.client.get<LarkData<{ content: string }>>(
83
+ `docs/v1/content?${buildURLData({ doc_type: 'docx', doc_token, content_type, lang })}`
84
+ ));
85
+ return body!.data!.content;
86
+ }
87
+
88
+ @toggle('downloading')
89
+ async getOneBlocks(id: string, resolveFileURL?: FileURLResolver) {
90
+ const { client, domain } = this;
91
+
92
+ class MyDocumentBlockModel extends DocumentBlockModel {
93
+ client = client;
94
+ }
95
+ return new MyDocumentBlockModel(domain, id).getRenderableAll(resolveFileURL);
96
+ }
97
+
98
+ @toggle('uploading')
99
+ async updateOneBlocks(id: string, markUpDown: string, user_id_type: UserIdType = 'open_id') {
100
+ const { client, domain } = this;
101
+
102
+ class MyDocumentBlockModel extends DocumentBlockModel {
103
+ client = client;
104
+ }
105
+ const blockStore = new MyDocumentBlockModel(domain, id);
106
+
107
+ await blockStore.removeAll();
108
+
109
+ return blockStore.insert(markUpDown, 0, undefined, user_id_type);
110
+ }
111
+ }
112
+
113
+ export abstract class DocumentBlockModel extends Stream<Block<any, any, any>>(ListModel) {
114
+ constructor(
115
+ public domain: string,
116
+ public documentId: string
117
+ ) {
118
+ super();
119
+ this.baseURI = `docx/v1/documents/${documentId}/blocks`;
120
+ }
121
+
122
+ openStream() {
123
+ return createPageStream<Block<any, any, any>>(
124
+ this.client,
125
+ this.baseURI,
126
+ total => (this.totalCount = total)
127
+ );
128
+ }
129
+
43
130
  #createLinkElement = (
44
131
  url: string,
45
132
  content = url,
@@ -229,12 +316,72 @@ export abstract class DocumentModel extends BaseListModel<Document> {
229
316
  /**
230
317
  * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document/list}
231
318
  */
232
- async getOneBlocks(id: string, resolveFileURL?: FileURLResolver) {
233
- const stream = createPageStream<Block<any, any, any>>(
234
- this.client,
235
- `docx/v1/documents/${id}/blocks`,
236
- total => void total
319
+ @toggle('downloading')
320
+ getRenderableAll(resolveFileURL?: FileURLResolver) {
321
+ return Array.fromAsync<Block<any, any, any>>(this.#resolveBlocks(this, resolveFileURL));
322
+ }
323
+
324
+ /**
325
+ * @see {@link https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document/convert}
326
+ */
327
+ @toggle('downloading')
328
+ async convertFrom(markUpDown: string, user_id_type: UserIdType = 'open_id') {
329
+ type ConvertResult = {
330
+ first_level_block_ids: string[];
331
+ blocks: Block<any, any>[];
332
+ block_id_to_image_urls: Record<'block_id' | 'image_url', string>[];
333
+ };
334
+ const { body } = await this.client.post<LarkData<ConvertResult>>(
335
+ `docx/v1/documents/blocks/convert?${buildURLData({ user_id_type })}`,
336
+ { content_type: 'markdown', content: markUpDown }
337
+ );
338
+ return body!.data!;
339
+ }
340
+
341
+ @toggle('downloading')
342
+ async getRoot() {
343
+ for await (const block of this)
344
+ if (block.block_type === BlockType.page) return block as PageBlock;
345
+ }
346
+
347
+ /**
348
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/docs/docx-v1/document-block/batch_delete}
349
+ */
350
+ @toggle('uploading')
351
+ async removeAll() {
352
+ const rootBlock = await this.getRoot();
353
+
354
+ if (rootBlock?.children?.[0])
355
+ await this.client.delete<LarkData<DocumentBlockUpdateResult>>(
356
+ `${this.baseURI}/${rootBlock.block_id}/children/batch_delete`,
357
+ { start_index: 0, end_index: rootBlock.children.length }
358
+ );
359
+ }
360
+
361
+ /**
362
+ * @see {@link https://open.feishu.cn/document/docs/docs/document-block/create-2}
363
+ */
364
+ @toggle('uploading')
365
+ async insert(
366
+ markUpDown: string,
367
+ index = -1,
368
+ rootBlockId?: string,
369
+ user_id_type: UserIdType = 'open_id'
370
+ ) {
371
+ const { first_level_block_ids: children_id, blocks } = await this.convertFrom(
372
+ markUpDown,
373
+ user_id_type
374
+ );
375
+ rootBlockId ||= (await this.getRoot())?.block_id;
376
+
377
+ type DescendantResult = DocumentBlockUpdateResult & {
378
+ children: Block<any, any, any>[];
379
+ block_id_relations: Record<`${'temporary_' | ''}block_id`, string>[];
380
+ };
381
+ const { body } = await this.client.post<LarkData<DescendantResult>>(
382
+ `${this.baseURI}/${rootBlockId}/descendant?${buildURLData({ user_id_type })}`,
383
+ { index, children_id, descendants: blocks }
237
384
  );
238
- return Array.fromAsync(this.#resolveBlocks(stream, resolveFileURL));
385
+ return body!.data!;
239
386
  }
240
387
  }
@@ -13,3 +13,8 @@ export interface Document extends Record<'document_id' | 'title', string> {
13
13
  boolean
14
14
  >;
15
15
  }
16
+
17
+ export interface DocumentBlockUpdateResult {
18
+ document_revision_id: number;
19
+ client_token: string;
20
+ }
@@ -13,13 +13,12 @@ export abstract class ChatListModel extends Stream<ChatMeta>(ListModel) {
13
13
  /**
14
14
  * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/list}
15
15
  */
16
- async *openStream() {
17
- for await (const item of createPageStream<ChatMeta>(
16
+ openStream() {
17
+ return createPageStream<ChatMeta>(
18
18
  this.client,
19
19
  this.baseURI,
20
20
  total => (this.totalCount = total)
21
- ))
22
- yield item;
21
+ );
23
22
  }
24
23
 
25
24
  /**
@@ -28,9 +27,7 @@ export abstract class ChatListModel extends Stream<ChatMeta>(ListModel) {
28
27
  @toggle('uploading')
29
28
  async updateOne({ chat_id }: NewData<ChatMeta>) {
30
29
  const { body } = await (chat_id
31
- ? this.client.put<LarkData<ChatMeta>>(
32
- `${this.baseURI}/chats/${chat_id}`
33
- )
30
+ ? this.client.put<LarkData<ChatMeta>>(`${this.baseURI}/chats/${chat_id}`)
34
31
  : this.client.post<LarkData<ChatMeta>>(
35
32
  `${this.baseURI}/chats?${buildURLData({
36
33
  set_bot_manager: true
@@ -50,23 +47,19 @@ export abstract class MessageListModel extends Stream<ChatMessage>(ListModel) {
50
47
  /**
51
48
  * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/list}
52
49
  */
53
- async *openStream() {
54
- for await (const item of createPageStream<ChatMessage>(
50
+ openStream() {
51
+ return createPageStream<ChatMessage>(
55
52
  this.client,
56
53
  this.baseURI,
57
54
  total => (this.totalCount = total)
58
- ))
59
- yield item;
55
+ );
60
56
  }
61
57
 
62
58
  /**
63
59
  * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/create
64
60
  */
65
61
  @toggle('uploading')
66
- async createOne({
67
- msg_type,
68
- content
69
- }: Omit<SendChatMessage, 'receive_id'>) {
62
+ async createOne({ msg_type, content }: Omit<SendChatMessage, 'receive_id'>) {
70
63
  const { body } = await this.client.post<LarkData<ChatMessage>>(
71
64
  `${this.baseURI}?${buildURLData({
72
65
  receive_id_type: 'chat_id'
@@ -33,15 +33,14 @@ export abstract class TaskModel extends Stream<Task, TaskFilter>(ListModel) {
33
33
  user_id_type = 'union_id',
34
34
  ...rest
35
35
  }: TaskFilter) {
36
- if (resource_type === 'my_tasks') {
37
- const stream = createPageStream<Task>(
36
+ if (resource_type === 'my_tasks')
37
+ yield* createPageStream<Task>(
38
38
  this.client,
39
39
  this.baseURI,
40
40
  total => (this.totalCount = total),
41
41
  { type: resource_type, user_id_type, ...rest }
42
42
  );
43
- for await (const item of stream) yield item;
44
- } else {
43
+ else {
45
44
  const stream = createPageStream<TaskSummary>(
46
45
  this.client,
47
46
  `task/v2/tasklists/${resource_id}/tasks`,
@@ -89,14 +88,13 @@ export abstract class TaskListModel extends Stream<TaskList, TaskListFilter>(Lis
89
88
  /**
90
89
  * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/tasklist/list}
91
90
  */
92
- async *openStream({ user_id_type = 'union_id' }: TaskListFilter) {
93
- for await (const item of createPageStream<TaskList>(
91
+ openStream({ user_id_type = 'union_id' }: TaskListFilter) {
92
+ return createPageStream<TaskList>(
94
93
  this.client,
95
94
  this.baseURI,
96
95
  total => (this.totalCount = total),
97
96
  { user_id_type }
98
- ))
99
- yield item;
97
+ );
100
98
  }
101
99
 
102
100
  /**
@@ -128,6 +126,7 @@ export abstract class TaskListModel extends Stream<TaskList, TaskListFilter>(Lis
128
126
  update_fields: Object.keys(tasklist)
129
127
  })
130
128
  : await this.client.post<LarkData<{ tasklist: TaskList }>>(path, tasklist);
129
+
131
130
  return body!.data!.tasklist;
132
131
  }
133
132
  }
@@ -157,7 +156,6 @@ export abstract class TaskListSectionModel extends Stream<TaskListSection, TaskL
157
156
  user_id_type
158
157
  }
159
158
  );
160
-
161
159
  for await (const { guid } of stream) yield await this.getOne(guid);
162
160
  }
163
161
 
@@ -206,18 +204,17 @@ export abstract class TaskFieldModel extends Stream<TaskField, TaskFieldFilter>(
206
204
  /**
207
205
  * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/custom_field/list}
208
206
  */
209
- async *openStream({
207
+ openStream({
210
208
  resource_type = 'tasklist',
211
209
  resource_id,
212
210
  user_id_type = 'union_id'
213
211
  }: TaskFieldFilter) {
214
- for await (const item of createPageStream<TaskField>(
212
+ return createPageStream<TaskField>(
215
213
  this.client,
216
214
  this.baseURI,
217
215
  total => (this.totalCount = total),
218
216
  { resource_type, resource_id, user_id_type }
219
- ))
220
- yield item;
217
+ );
221
218
  }
222
219
 
223
220
  /**
@@ -246,6 +243,7 @@ export abstract class TaskFieldModel extends Stream<TaskField, TaskFieldFilter>(
246
243
 
247
244
  for (const body of targets)
248
245
  await this.client.post(`${this.baseURI}/${custom_field.guid}/add`, body);
246
+
249
247
  return custom_field;
250
248
  }
251
249
  }