mobx-lark 2.0.0 → 2.1.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/ReadMe.md +3 -6
- package/dist/Lark.d.ts +19 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module/BITable/index.d.ts +45 -49
- package/dist/module/BITable/type.d.ts +7 -1
- package/dist/module/BITable/utility.d.ts +10 -0
- package/dist/module/InstantMessenger/index.d.ts +8 -8
- package/dist/module/Task/index.d.ts +16 -16
- package/dist/type.d.ts +2 -2
- package/package.json +16 -21
- package/src/Lark.ts +51 -27
- package/src/module/BITable/index.ts +22 -40
- package/src/module/BITable/type.ts +9 -1
- package/src/module/BITable/utility.ts +57 -0
- package/src/module/base.ts +1 -1
- package/src/type.ts +5 -1
|
@@ -13,51 +13,22 @@ import { UserIdType } from '../../type';
|
|
|
13
13
|
import { createPageStream } from '../base';
|
|
14
14
|
import {
|
|
15
15
|
BITable,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
TableCellText,
|
|
16
|
+
LarkFormData,
|
|
17
|
+
TableFormView,
|
|
19
18
|
TableRecord,
|
|
20
19
|
TableRecordData,
|
|
21
20
|
TableRecordFields,
|
|
22
21
|
TableView
|
|
23
22
|
} from './type';
|
|
23
|
+
import { makeSimpleFilter } from './utility';
|
|
24
24
|
|
|
25
25
|
export * from './type';
|
|
26
|
+
export * from './utility';
|
|
26
27
|
|
|
27
|
-
export type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
export function makeSimpleFilter(
|
|
33
|
-
data: DataObject,
|
|
34
|
-
operator: FilterOperator = 'contains',
|
|
35
|
-
relation: 'AND' | 'OR' = 'AND'
|
|
36
|
-
) {
|
|
37
|
-
const list = Object.entries(data)
|
|
38
|
-
.map(
|
|
39
|
-
([key, value]) =>
|
|
40
|
-
value != null &&
|
|
41
|
-
(value instanceof Array ? value : [value]).map(
|
|
42
|
-
(item: string) =>
|
|
43
|
-
`CurrentValue.[${key}]` +
|
|
44
|
-
(operator === 'contains'
|
|
45
|
-
? `.contains("${item}")`
|
|
46
|
-
: `${operator}${JSON.stringify(item)}`)
|
|
47
|
-
)
|
|
48
|
-
)
|
|
49
|
-
.filter(Boolean)
|
|
50
|
-
.flat() as string[];
|
|
51
|
-
|
|
52
|
-
return list[1] ? `${relation}(${list})` : list[0];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const normalizeText = (
|
|
56
|
-
value: TableCellText | TableCellLink | TableCellRelation
|
|
57
|
-
) =>
|
|
58
|
-
(value && typeof value === 'object' && 'text' in value && value.text) || '';
|
|
59
|
-
|
|
60
|
-
export type BiBaseData = Omit<TableRecord<{}>, 'record_id' | 'fields'>;
|
|
28
|
+
export type BiBaseData = Omit<
|
|
29
|
+
TableRecord<{}>,
|
|
30
|
+
`record_${'id' | 'url'}` | 'fields'
|
|
31
|
+
>;
|
|
61
32
|
|
|
62
33
|
export interface BiDataQueryOptions {
|
|
63
34
|
text_field_as_array?: boolean;
|
|
@@ -229,8 +200,11 @@ interface BiSearchModel
|
|
|
229
200
|
|
|
230
201
|
export type BiSearchModelClass = Constructor<BiSearchModel>;
|
|
231
202
|
|
|
232
|
-
export function BiTableView
|
|
233
|
-
|
|
203
|
+
export function BiTableView<
|
|
204
|
+
T extends TableView['view_type'],
|
|
205
|
+
D extends T extends 'form' ? TableFormView : TableView
|
|
206
|
+
>(type = 'grid' as T) {
|
|
207
|
+
abstract class BiTableViewModel extends Stream<D>(ListModel) {
|
|
234
208
|
constructor(appId: string, tableId: string) {
|
|
235
209
|
super();
|
|
236
210
|
this.baseURI = `bitable/v1/apps/${appId}/tables/${tableId}/views`;
|
|
@@ -238,6 +212,7 @@ export function BiTableView() {
|
|
|
238
212
|
|
|
239
213
|
/**
|
|
240
214
|
* @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table-view/list}
|
|
215
|
+
* @see {@link https://open.feishu.cn/document/server-docs/docs/bitable-v1/form/get}
|
|
241
216
|
*/
|
|
242
217
|
async *openStream() {
|
|
243
218
|
for await (const item of createPageStream<TableView>(
|
|
@@ -245,7 +220,14 @@ export function BiTableView() {
|
|
|
245
220
|
this.baseURI,
|
|
246
221
|
total => (this.totalCount = total)
|
|
247
222
|
))
|
|
248
|
-
|
|
223
|
+
if (type !== 'form') {
|
|
224
|
+
if (item.view_type === type) yield item as D;
|
|
225
|
+
} else if (item.view_type === 'form') {
|
|
226
|
+
const { body } = await this.client.get<LarkFormData>(
|
|
227
|
+
this.baseURI.replace(/views$/, `forms/${item.view_id}`)
|
|
228
|
+
);
|
|
229
|
+
yield body!.data!.form as D;
|
|
230
|
+
}
|
|
249
231
|
}
|
|
250
232
|
}
|
|
251
233
|
return BiTableViewModel;
|
|
@@ -10,9 +10,17 @@ export interface BITable extends RevisionTable {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface TableView extends Record<'view_id' | 'view_name', string> {
|
|
13
|
-
view_type: 'grid' | 'form';
|
|
13
|
+
view_type: 'grid' | 'kanban' | 'gallery' | 'gantt' | 'form';
|
|
14
14
|
}
|
|
15
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
|
+
|
|
16
24
|
export interface TableCellText {
|
|
17
25
|
type: 'text';
|
|
18
26
|
text: string;
|
|
@@ -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
|
+
}
|
package/src/module/base.ts
CHANGED
package/src/type.ts
CHANGED
|
@@ -32,7 +32,10 @@ export type TenantAccessToken = LarkData<
|
|
|
32
32
|
|
|
33
33
|
export type UserIdType = `${'open' | 'union' | 'user'}_id`;
|
|
34
34
|
|
|
35
|
-
export type LocaleUser = Record
|
|
35
|
+
export type LocaleUser = Record<
|
|
36
|
+
`${'' | 'en_'}name` | `${'' | 'enterprise_'}email`,
|
|
37
|
+
string
|
|
38
|
+
>;
|
|
36
39
|
|
|
37
40
|
export interface UserMeta
|
|
38
41
|
extends LocaleUser,
|
|
@@ -41,6 +44,7 @@ export interface UserMeta
|
|
|
41
44
|
| UserIdType
|
|
42
45
|
| 'mobile'
|
|
43
46
|
| 'tenant_key'
|
|
47
|
+
| 'employee_no'
|
|
44
48
|
| `${'access' | 'refresh'}_token`,
|
|
45
49
|
string
|
|
46
50
|
>,
|