Skip to content

Commit

Permalink
[refactor] roll back to better biTable.getOne()
Browse files Browse the repository at this point in the history
[add] Table Cell Location type & Dependency badge
[optimize] update Upstream packages
  • Loading branch information
TechQuery committed Aug 8, 2023
1 parent 3ce3243 commit d9b2404
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ yarn-error.log
dist/
docs/
.env
.vscode/settings.json
13 changes: 8 additions & 5 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

Unofficial [TypeScript][1] SDK for [FeiShu/Lark API][2], which is based on [MobX-RESTful][3].

[![CI & CD](https://github.com/idea2app/MobX-Lark/actions/workflows/main.yml/badge.svg)][4]
[![NPM Dependency](https://img.shields.io/librariesio/github/idea2app/MobX-Lark.svg)][4]
[![CI & CD](https://github.com/idea2app/MobX-Lark/actions/workflows/main.yml/badge.svg)][5]

[![NPM](https://nodei.co/npm/mobx-lark.png?downloads=true&downloadRank=true&stars=true)][5]
[![NPM](https://nodei.co/npm/mobx-lark.png?downloads=true&downloadRank=true&stars=true)][6]

## Usage

Expand All @@ -13,7 +14,8 @@ Unofficial [TypeScript][1] SDK for [FeiShu/Lark API][2], which is based on [MobX

## User cases

1. [KaiYuanShe web-site](https://github.com/kaiyuanshe/kaiyuanshe.github.io/blob/main/models)
1. [idea2app web-site](https://github.com/idea2app/idea2app.github.io/tree/main/models)
2. [KaiYuanShe web-site](https://github.com/kaiyuanshe/kaiyuanshe.github.io/tree/main/models)

## Related with

Expand All @@ -22,5 +24,6 @@ Unofficial [TypeScript][1] SDK for [FeiShu/Lark API][2], which is based on [MobX
[1]: https://www.typescriptlang.org/
[2]: https://open.feishu.cn/
[3]: https://github.com/idea2app/MobX-RESTful
[4]: https://github.com/idea2app/MobX-Lark/actions/workflows/main.yml
[5]: https://nodei.co/npm/mobx-lark/
[4]: https://libraries.io/npm/mobx-lark
[5]: https://github.com/idea2app/MobX-Lark/actions/workflows/main.yml
[6]: https://nodei.co/npm/mobx-lark/
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-lark",
"version": "1.0.0-rc.0",
"version": "1.0.0-rc.3",
"license": "LGPL-3.0",
"author": "shiy2008@gmail.com",
"description": "Unofficial TypeScript SDK for FeiShu/Lark API, which is based on MobX-RESTful.",
Expand Down Expand Up @@ -30,21 +30,21 @@
"koajax": "^0.8.4",
"mobx-restful": "^0.6.5",
"node-fetch": "^2.6.12",
"regenerator-runtime": "^0.13.11",
"web-utility": "^4.0.1"
"regenerator-runtime": "^0.14.0",
"web-utility": "^4.1.0"
},
"peerDependencies": {
"mobx": ">=4 <6"
},
"devDependencies": {
"@types/node": "^18.17.0",
"@types/node": "^18.17.3",
"@types/node-fetch": "^2.6.4",
"dotenv": "^16.3.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.3",
"mobx": "^5.15.7",
"parcel": "~2.6.2",
"prettier": "^3.0.0",
"prettier": "^3.0.1",
"ts-node": "^10.9.1",
"typedoc": "^0.24.8",
"typedoc-plugin-mdn-links": "^3.0.3",
Expand Down
44 changes: 24 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 22 additions & 20 deletions src/module/BITable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataObject, ListModel, NewData, Stream, toggle } from 'mobx-restful';
import { Constructor, isEmpty } from 'web-utility';
import { isEmpty } from 'web-utility';

import {
BITableList,
Expand Down Expand Up @@ -170,7 +170,27 @@ export function BiTable() {
this.baseURI = `bitable/v1/apps/${id}/tables`;
}

tableMap = {} as Record<string, ListModel<{}>>;
currentDataTable?: ListModel<DataObject>;

async getOne<T extends DataObject>(
tableName: string,
DataTableClass?: BiDataTableClass<T>
) {
const { allItems } = this;

const list = allItems[0] ? allItems : await this.getAll();

const table = list.find(({ name }) => name === tableName);

if (!table) throw new URIError(`Table "${tableName}" is not found`);

if (DataTableClass instanceof Function)
this.currentDataTable = Reflect.construct(DataTableClass, [
this.id,
table.table_id
]);
return (this.currentOne = table);
}

/**
* @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app-table/list}
Expand All @@ -183,24 +203,6 @@ export function BiTable() {
))
yield item;
}

async getAllTables<
T extends Record<string, Constructor<ListModel<DataObject>>>
>(map: T) {
const list = await this.getAll();

for (const { table_id, name } of list)
if (map[name] instanceof Function)
this.tableMap[name] = Reflect.construct(map[name], [
this.id,
table_id
]);

type UnwrapMap<T> = {
[K in keyof T]: T[K] extends Constructor<infer M> ? M : never;
};
return this.tableMap as UnwrapMap<T>;
}
}
return BiTableModel;
}
12 changes: 12 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ export interface TableCellText {
text: string;
}

export type TableCellLocation = Record<
| 'name'
| 'pname'
| 'cityname'
| 'adname'
| 'address'
| 'full_address'
| 'location',
string
>;

export interface TableCellLink extends Record<'link' | 'text', string> {
type: 'url';
}
Expand Down Expand Up @@ -161,6 +172,7 @@ export type TableCellValue =
| string
| number
| boolean
| TableCellLocation
| TableCellLink
| (
| string
Expand Down

0 comments on commit d9b2404

Please sign in to comment.