mobx-lark 2.0.0 → 2.1.1

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,112 +1,120 @@
1
- import { LarkData, LocaleUser } from '../../type';
2
-
3
- export interface RevisionTable {
4
- name: string;
5
- revision: number;
6
- }
7
-
8
- export interface BITable extends RevisionTable {
9
- table_id: string;
10
- }
11
-
12
- export interface TableView extends Record<'view_id' | 'view_name', string> {
13
- view_type: 'grid' | 'form';
14
- }
15
-
16
- export interface TableCellText {
17
- type: 'text';
18
- text: string;
19
- }
20
-
21
- export type TableCellLocation = Record<
22
- | 'name'
23
- | 'pname'
24
- | 'cityname'
25
- | 'adname'
26
- | 'address'
27
- | 'full_address'
28
- | 'location',
29
- string
30
- >;
31
-
32
- export interface TableCellLink extends Record<'link' | 'text', string> {
33
- type: 'url';
34
- }
35
-
36
- export interface TableCellMedia
37
- extends Record<'file_token' | 'name' | `${'' | 'tmp_'}url`, string> {
38
- type: `${string}/${string}`;
39
- size: number;
40
- }
41
-
42
- export interface TableCellAttachment
43
- extends Pick<TableCellMedia, 'name' | 'size'>,
44
- Record<'id' | 'attachmentToken', string>,
45
- Record<'height' | 'timeStamp' | 'width', number> {
46
- mimeType: TableCellMedia['type'];
47
- }
48
-
49
- export interface TableCellUser extends LocaleUser {
50
- id: string;
51
- }
52
-
53
- export type TableCellGroup = Record<'id' | 'name' | 'avatar_url', string>;
54
-
55
- export interface TableCellMetion
56
- extends Record<'mentionType' | 'text', string> {
57
- type: 'mention';
58
- }
59
-
60
- export interface TableCellUserMetion
61
- extends TableCellMetion,
62
- Record<'name' | 'token', string> {
63
- mentionType: 'User';
64
- mentionNotify: boolean;
65
- }
66
-
67
- export interface TableCellDocumentMetion
68
- extends TableCellMetion,
69
- Record<'link' | 'token', string> {
70
- mentionType: 'Bitable';
71
- }
72
-
73
- export interface TableCellRelation extends TableCellText {
74
- table_id: string;
75
- record_ids: string[];
76
- text_arr: string[];
77
- }
78
-
79
- export type TableCellObject =
80
- | TableCellLocation
81
- | TableCellText
82
- | TableCellLink
83
- | TableCellMedia
84
- | TableCellAttachment
85
- | TableCellUser
86
- | TableCellGroup
87
- | TableCellUserMetion
88
- | TableCellDocumentMetion
89
- | TableCellRelation;
90
-
91
- export type TableCellValue =
92
- | string
93
- | number
94
- | boolean
95
- | TableCellObject
96
- | (string | TableCellObject)[]
97
- | null;
98
-
99
- export type TableRecordFields = Record<string, TableCellValue>;
100
-
101
- export interface TableRecord<T extends TableRecordFields>
102
- extends Record<'id' | 'record_id', string> {
103
- created_by: TableCellUser;
104
- created_time: number;
105
- last_modified_by?: TableCellUser;
106
- last_modified_time?: number;
107
- fields: T;
108
- }
109
-
110
- export type TableRecordData<T extends TableRecordFields> = LarkData<{
111
- record: TableRecord<T>;
112
- }>;
1
+ import { LarkData, LocaleUser } from '../../type';
2
+
3
+ export interface RevisionTable {
4
+ name: string;
5
+ revision: number;
6
+ }
7
+
8
+ export interface BITable extends RevisionTable {
9
+ table_id: string;
10
+ }
11
+
12
+ export interface TableView extends Record<'view_id' | 'view_name', string> {
13
+ view_type: 'grid' | 'kanban' | 'gallery' | 'gantt' | 'form';
14
+ }
15
+
16
+ export interface TableFormView
17
+ extends Record<'name' | 'description' | 'shared_url', string>,
18
+ Record<'shared' | 'submit_limit_once', boolean> {
19
+ shared_limit: 'tenant_editable';
20
+ }
21
+
22
+ export type LarkFormData = LarkData<{ form: TableFormView }>;
23
+
24
+ export interface TableCellText {
25
+ type: 'text';
26
+ text: string;
27
+ }
28
+
29
+ export type TableCellLocation = Record<
30
+ | 'name'
31
+ | 'pname'
32
+ | 'cityname'
33
+ | 'adname'
34
+ | 'address'
35
+ | 'full_address'
36
+ | 'location',
37
+ string
38
+ >;
39
+
40
+ export interface TableCellLink extends Record<'link' | 'text', string> {
41
+ type: 'url';
42
+ }
43
+
44
+ export interface TableCellMedia
45
+ extends Record<'file_token' | 'name' | `${'' | 'tmp_'}url`, string> {
46
+ type: `${string}/${string}`;
47
+ size: number;
48
+ }
49
+
50
+ export interface TableCellAttachment
51
+ extends Pick<TableCellMedia, 'name' | 'size'>,
52
+ Record<'id' | 'attachmentToken', string>,
53
+ Record<'height' | 'timeStamp' | 'width', number> {
54
+ mimeType: TableCellMedia['type'];
55
+ }
56
+
57
+ export interface TableCellUser extends LocaleUser {
58
+ id: string;
59
+ }
60
+
61
+ export type TableCellGroup = Record<'id' | 'name' | 'avatar_url', string>;
62
+
63
+ export interface TableCellMetion
64
+ extends Record<'mentionType' | 'text', string> {
65
+ type: 'mention';
66
+ }
67
+
68
+ export interface TableCellUserMetion
69
+ extends TableCellMetion,
70
+ Record<'name' | 'token', string> {
71
+ mentionType: 'User';
72
+ mentionNotify: boolean;
73
+ }
74
+
75
+ export interface TableCellDocumentMetion
76
+ extends TableCellMetion,
77
+ Record<'link' | 'token', string> {
78
+ mentionType: 'Bitable';
79
+ }
80
+
81
+ export interface TableCellRelation extends TableCellText {
82
+ table_id: string;
83
+ record_ids: string[];
84
+ text_arr: string[];
85
+ }
86
+
87
+ export type TableCellObject =
88
+ | TableCellLocation
89
+ | TableCellText
90
+ | TableCellLink
91
+ | TableCellMedia
92
+ | TableCellAttachment
93
+ | TableCellUser
94
+ | TableCellGroup
95
+ | TableCellUserMetion
96
+ | TableCellDocumentMetion
97
+ | TableCellRelation;
98
+
99
+ export type TableCellValue =
100
+ | string
101
+ | number
102
+ | boolean
103
+ | TableCellObject
104
+ | (string | TableCellObject)[]
105
+ | null;
106
+
107
+ export type TableRecordFields = Record<string, TableCellValue>;
108
+
109
+ export interface TableRecord<T extends TableRecordFields>
110
+ extends Record<'id' | 'record_id', string> {
111
+ created_by: TableCellUser;
112
+ created_time: number;
113
+ last_modified_by?: TableCellUser;
114
+ last_modified_time?: number;
115
+ fields: T;
116
+ }
117
+
118
+ export type TableRecordData<T extends TableRecordFields> = LarkData<{
119
+ record: TableRecord<T>;
120
+ }>;
@@ -0,0 +1,57 @@
1
+ import { DataObject } from 'mobx-restful';
2
+ import {
3
+ TableCellLink,
4
+ TableCellLocation,
5
+ TableCellRelation,
6
+ TableCellText
7
+ } from './type';
8
+
9
+ export type FilterOperator = '<' | '<=' | '=' | '!=' | '=>' | '>' | 'contains';
10
+
11
+ /**
12
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/filter
13
+ */
14
+ export function makeSimpleFilter(
15
+ data: DataObject,
16
+ operator: FilterOperator = 'contains',
17
+ relation: 'AND' | 'OR' = 'AND'
18
+ ) {
19
+ const list = Object.entries(data)
20
+ .map(
21
+ ([key, value]) =>
22
+ value != null &&
23
+ (value instanceof Array ? value : [value]).map(
24
+ (item: string) =>
25
+ `CurrentValue.[${key}]` +
26
+ (operator === 'contains'
27
+ ? `.contains("${item}")`
28
+ : `${operator}${JSON.stringify(item)}`)
29
+ )
30
+ )
31
+ .filter(Boolean)
32
+ .flat() as string[];
33
+
34
+ return list[1] ? `${relation}(${list})` : list[0];
35
+ }
36
+
37
+ export const normalizeText = (
38
+ value: TableCellText | TableCellLink | TableCellRelation
39
+ ) =>
40
+ (value && typeof value === 'object' && 'text' in value && value.text) || '';
41
+
42
+ export const normalizeTextArray = (list: TableCellText[]) =>
43
+ list.reduce(
44
+ (sum, item) => {
45
+ if (item.text === ',') sum.push('');
46
+ else sum[sum.length - 1] += normalizeText(item);
47
+
48
+ return sum;
49
+ },
50
+ ['']
51
+ );
52
+ export function coordinateOf(location: TableCellLocation): [number, number] {
53
+ const [longitude, latitude] =
54
+ (location as TableCellLocation)?.location.split(',') || [];
55
+
56
+ return [+latitude, +longitude];
57
+ }
@@ -1,82 +1,82 @@
1
- import { ListModel, NewData, Stream, toggle } from 'mobx-restful';
2
- import { buildURLData } from 'web-utility';
3
-
4
- import { LarkData } from '../../type';
5
- import { createPageStream } from '../base';
6
- import { ChatMessage, ChatMeta, SendChatMessage } from './type';
7
-
8
- export * from './type';
9
-
10
- export abstract class ChatListModel extends Stream<ChatMeta>(ListModel) {
11
- baseURI = 'im/v1/chats';
12
-
13
- /**
14
- * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/list}
15
- */
16
- async *openStream() {
17
- for await (const item of createPageStream<ChatMeta>(
18
- this.client,
19
- this.baseURI,
20
- total => (this.totalCount = total)
21
- ))
22
- yield item;
23
- }
24
-
25
- /**
26
- * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/create
27
- */
28
- @toggle('uploading')
29
- async updateOne({ chat_id }: NewData<ChatMeta>) {
30
- const { body } = await (chat_id
31
- ? this.client.put<LarkData<ChatMeta>>(
32
- `${this.baseURI}/chats/${chat_id}`
33
- )
34
- : this.client.post<LarkData<ChatMeta>>(
35
- `${this.baseURI}/chats?${buildURLData({
36
- set_bot_manager: true
37
- })}`
38
- ));
39
- return (this.currentOne = body!.data!);
40
- }
41
- }
42
-
43
- export abstract class MessageListModel extends Stream<ChatMessage>(ListModel) {
44
- baseURI = 'im/v1/messages';
45
-
46
- constructor(public chatId: string) {
47
- super();
48
- }
49
-
50
- /**
51
- * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/list}
52
- */
53
- async *openStream() {
54
- for await (const item of createPageStream<ChatMessage>(
55
- this.client,
56
- this.baseURI,
57
- total => (this.totalCount = total)
58
- ))
59
- yield item;
60
- }
61
-
62
- /**
63
- * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/create
64
- */
65
- @toggle('uploading')
66
- async createOne({
67
- msg_type,
68
- content
69
- }: Omit<SendChatMessage, 'receive_id'>) {
70
- const { body } = await this.client.post<LarkData<ChatMessage>>(
71
- `${this.baseURI}?${buildURLData({
72
- receive_id_type: 'chat_id'
73
- })}`,
74
- {
75
- receive_id: this.chatId,
76
- msg_type,
77
- content: JSON.stringify(content)
78
- }
79
- );
80
- return (this.currentOne = body!.data!);
81
- }
82
- }
1
+ import { ListModel, NewData, Stream, toggle } from 'mobx-restful';
2
+ import { buildURLData } from 'web-utility';
3
+
4
+ import { LarkData } from '../../type';
5
+ import { createPageStream } from '../base';
6
+ import { ChatMessage, ChatMeta, SendChatMessage } from './type';
7
+
8
+ export * from './type';
9
+
10
+ export abstract class ChatListModel extends Stream<ChatMeta>(ListModel) {
11
+ baseURI = 'im/v1/chats';
12
+
13
+ /**
14
+ * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/list}
15
+ */
16
+ async *openStream() {
17
+ for await (const item of createPageStream<ChatMeta>(
18
+ this.client,
19
+ this.baseURI,
20
+ total => (this.totalCount = total)
21
+ ))
22
+ yield item;
23
+ }
24
+
25
+ /**
26
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/create
27
+ */
28
+ @toggle('uploading')
29
+ async updateOne({ chat_id }: NewData<ChatMeta>) {
30
+ const { body } = await (chat_id
31
+ ? this.client.put<LarkData<ChatMeta>>(
32
+ `${this.baseURI}/chats/${chat_id}`
33
+ )
34
+ : this.client.post<LarkData<ChatMeta>>(
35
+ `${this.baseURI}/chats?${buildURLData({
36
+ set_bot_manager: true
37
+ })}`
38
+ ));
39
+ return (this.currentOne = body!.data!);
40
+ }
41
+ }
42
+
43
+ export abstract class MessageListModel extends Stream<ChatMessage>(ListModel) {
44
+ baseURI = 'im/v1/messages';
45
+
46
+ constructor(public chatId: string) {
47
+ super();
48
+ }
49
+
50
+ /**
51
+ * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/list}
52
+ */
53
+ async *openStream() {
54
+ for await (const item of createPageStream<ChatMessage>(
55
+ this.client,
56
+ this.baseURI,
57
+ total => (this.totalCount = total)
58
+ ))
59
+ yield item;
60
+ }
61
+
62
+ /**
63
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/create
64
+ */
65
+ @toggle('uploading')
66
+ async createOne({
67
+ msg_type,
68
+ content
69
+ }: Omit<SendChatMessage, 'receive_id'>) {
70
+ const { body } = await this.client.post<LarkData<ChatMessage>>(
71
+ `${this.baseURI}?${buildURLData({
72
+ receive_id_type: 'chat_id'
73
+ })}`,
74
+ {
75
+ receive_id: this.chatId,
76
+ msg_type,
77
+ content: JSON.stringify(content)
78
+ }
79
+ );
80
+ return (this.currentOne = body!.data!);
81
+ }
82
+ }
@@ -1,60 +1,60 @@
1
- import { TranslationMap } from '../../../type';
2
- import { ChatMessageContent } from './message';
3
-
4
- export * from './message';
5
-
6
- export type ChatPermission = 'all_members' | 'only_owner' | 'not_anyone';
7
-
8
- export interface CreateChatMeta
9
- extends Record<'owner_id' | 'avatar' | 'name' | 'description', string>,
10
- Record<`${'join' | 'leave'}_message_visibility`, ChatPermission>,
11
- Record<`${'user' | 'bot'}_id_list`, string[]> {
12
- chat_mode: 'group';
13
- chat_type: 'private' | 'public';
14
- i18n_names: TranslationMap;
15
- external: boolean;
16
- membership_approval: 'no_approval_required' | 'approval_required';
17
- }
18
-
19
- export interface ChatMeta
20
- extends CreateChatMeta,
21
- Record<'tenant_key' | 'chat_id', string>,
22
- Record<
23
- `${'add_member' | 'at_all' | 'edit' | 'moderation'}_permission`,
24
- ChatPermission
25
- > {
26
- owner_id_type: 'user_id';
27
- chat_tag: 'inner';
28
- share_card_permission: 'allowed';
29
- }
30
-
31
- export type ChatMessageType = 'text' | 'card';
32
-
33
- export interface SendChatMessage {
34
- msg_type: ChatMessageType;
35
- content: ChatMessageContent;
36
- receive_id: string;
37
- }
38
-
39
- export interface ChatSender extends Record<'id' | 'tenant_key', string> {
40
- id_type: 'open_id' | 'app_id';
41
- sender_type: 'app';
42
- }
43
-
44
- export type ChatMetion = Pick<ChatSender, 'id' | 'id_type' | 'tenant_key'> &
45
- Record<'key' | 'name', string>;
46
-
47
- export interface ChatMessage
48
- extends Pick<SendChatMessage, 'msg_type'>,
49
- Record<`${'create' | 'update'}_time`, string>,
50
- Record<'deleted' | 'updated', boolean>,
51
- Record<
52
- `${'chat' | 'message' | 'upper_message' | 'root' | 'parent'}_id`,
53
- string
54
- > {
55
- sender: ChatSender;
56
- mentions: ChatMetion[];
57
- body: {
58
- content: `${ChatMessageType}:${string}`;
59
- };
60
- }
1
+ import { TranslationMap } from '../../../type';
2
+ import { ChatMessageContent } from './message';
3
+
4
+ export * from './message';
5
+
6
+ export type ChatPermission = 'all_members' | 'only_owner' | 'not_anyone';
7
+
8
+ export interface CreateChatMeta
9
+ extends Record<'owner_id' | 'avatar' | 'name' | 'description', string>,
10
+ Record<`${'join' | 'leave'}_message_visibility`, ChatPermission>,
11
+ Record<`${'user' | 'bot'}_id_list`, string[]> {
12
+ chat_mode: 'group';
13
+ chat_type: 'private' | 'public';
14
+ i18n_names: TranslationMap;
15
+ external: boolean;
16
+ membership_approval: 'no_approval_required' | 'approval_required';
17
+ }
18
+
19
+ export interface ChatMeta
20
+ extends CreateChatMeta,
21
+ Record<'tenant_key' | 'chat_id', string>,
22
+ Record<
23
+ `${'add_member' | 'at_all' | 'edit' | 'moderation'}_permission`,
24
+ ChatPermission
25
+ > {
26
+ owner_id_type: 'user_id';
27
+ chat_tag: 'inner';
28
+ share_card_permission: 'allowed';
29
+ }
30
+
31
+ export type ChatMessageType = 'text' | 'card';
32
+
33
+ export interface SendChatMessage {
34
+ msg_type: ChatMessageType;
35
+ content: ChatMessageContent;
36
+ receive_id: string;
37
+ }
38
+
39
+ export interface ChatSender extends Record<'id' | 'tenant_key', string> {
40
+ id_type: 'open_id' | 'app_id';
41
+ sender_type: 'app';
42
+ }
43
+
44
+ export type ChatMetion = Pick<ChatSender, 'id' | 'id_type' | 'tenant_key'> &
45
+ Record<'key' | 'name', string>;
46
+
47
+ export interface ChatMessage
48
+ extends Pick<SendChatMessage, 'msg_type'>,
49
+ Record<`${'create' | 'update'}_time`, string>,
50
+ Record<'deleted' | 'updated', boolean>,
51
+ Record<
52
+ `${'chat' | 'message' | 'upper_message' | 'root' | 'parent'}_id`,
53
+ string
54
+ > {
55
+ sender: ChatSender;
56
+ mentions: ChatMetion[];
57
+ body: {
58
+ content: `${ChatMessageType}:${string}`;
59
+ };
60
+ }