From d9b24045fb2c59486c31e664161c8e08a868fdde Mon Sep 17 00:00:00 2001 From: TechQuery Date: Wed, 9 Aug 2023 03:55:50 +0800 Subject: [PATCH] [refactor] roll back to better biTable.getOne() [add] Table Cell Location type & Dependency badge [optimize] update Upstream packages --- .gitignore | 1 + ReadMe.md | 13 ++++++++----- package.json | 10 +++++----- pnpm-lock.yaml | 44 +++++++++++++++++++++++-------------------- src/module/BITable.ts | 42 +++++++++++++++++++++-------------------- src/type.ts | 12 ++++++++++++ 6 files changed, 72 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index f4b89e3..33cb31a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ yarn-error.log dist/ docs/ .env +.vscode/settings.json \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index a646002..18f6582 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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 @@ -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 @@ -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/ diff --git a/package.json b/package.json index 21979b2..d1b214c 100644 --- a/package.json +++ b/package.json @@ -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.", @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5fbaed9..62327d9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,16 +18,16 @@ dependencies: specifier: ^2.6.12 version: 2.6.12 regenerator-runtime: - specifier: ^0.13.11 - version: 0.13.11 + specifier: ^0.14.0 + version: 0.14.0 web-utility: - specifier: ^4.0.1 - version: 4.0.1(typescript@5.1.6) + specifier: ^4.1.0 + version: 4.1.0(typescript@5.1.6) devDependencies: '@types/node': - specifier: ^18.17.0 - version: 18.17.0 + specifier: ^18.17.3 + version: 18.17.3 '@types/node-fetch': specifier: ^2.6.4 version: 2.6.4 @@ -47,11 +47,11 @@ devDependencies: specifier: ~2.6.2 version: 2.6.2 prettier: - specifier: ^3.0.0 - version: 3.0.0 + specifier: ^3.0.1 + version: 3.0.1 ts-node: specifier: ^10.9.1 - version: 10.9.1(@types/node@18.17.0)(typescript@5.1.6) + version: 10.9.1(@types/node@18.17.3)(typescript@5.1.6) typedoc: specifier: ^0.24.8 version: 0.24.8(typescript@5.1.6) @@ -1058,12 +1058,12 @@ packages: /@types/node-fetch@2.6.4: resolution: {integrity: sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg==} dependencies: - '@types/node': 18.17.0 + '@types/node': 18.17.3 form-data: 3.0.1 dev: true - /@types/node@18.17.0: - resolution: {integrity: sha512-GXZxEtOxYGFchyUzxvKI14iff9KZ2DI+A6a37o6EQevtg6uO9t+aUZKcaC1Te5Ng1OnLM7K9NVVj+FbecD9cJg==} + /@types/node@18.17.3: + resolution: {integrity: sha512-2x8HWtFk0S99zqVQABU9wTpr8wPoaDHZUcAkoTKH+nL7kPv3WUI9cRi/Kk5Mz4xdqXSqTkKP7IWNoQQYCnDsTA==} dev: true /@types/validator@13.7.17: @@ -1855,7 +1855,7 @@ packages: iterable-observer: 1.0.0 jsdom: 21.1.2 regenerator-runtime: 0.13.11 - web-utility: 4.0.1(typescript@5.1.6) + web-utility: 4.1.0(typescript@5.1.6) transitivePeerDependencies: - typescript dev: false @@ -2099,7 +2099,7 @@ packages: mobx: 5.15.7 reflect-metadata: 0.1.13 regenerator-runtime: 0.13.11 - web-utility: 4.0.1(typescript@5.1.6) + web-utility: 4.1.0(typescript@5.1.6) transitivePeerDependencies: - jsdom - typescript @@ -2341,8 +2341,8 @@ packages: posthtml-render: 3.0.0 dev: true - /prettier@3.0.0: - resolution: {integrity: sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==} + /prettier@3.0.1: + resolution: {integrity: sha512-fcOWSnnpCrovBsmFZIGIy9UqK2FaI7Hqax+DIO0A9UxeVoY4iweyaFjS5TavZN97Hfehph0nhsZnjlVKzEQSrQ==} engines: {node: '>=14'} hasBin: true dev: true @@ -2376,6 +2376,10 @@ packages: /regenerator-runtime@0.13.11: resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==} + /regenerator-runtime@0.14.0: + resolution: {integrity: sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA==} + dev: false + /requires-port@1.0.0: resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} dev: false @@ -2620,7 +2624,7 @@ packages: punycode: 2.3.0 dev: false - /ts-node@10.9.1(@types/node@18.17.0)(typescript@5.1.6): + /ts-node@10.9.1(@types/node@18.17.3)(typescript@5.1.6): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -2639,7 +2643,7 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 - '@types/node': 18.17.0 + '@types/node': 18.17.3 acorn: 8.10.0 acorn-walk: 8.2.0 arg: 4.1.3 @@ -2751,8 +2755,8 @@ packages: resolution: {integrity: sha512-DEAoo25RfSYMuTGc9vPJzZcZullwIqRDSI9LOy+fkCJPi6hykCnfKaXTuPBDuXAUcqHXyOgFtHNp/kB2FjYHbw==} dev: true - /web-utility@4.0.1(typescript@5.1.6): - resolution: {integrity: sha512-gQwLcgLdxT3gAgR9XXN+7Dz73r95r+Ph9CCfyvorgF4qeFvevkQXr0rj2RoMyeaPPu+9upe9zO/U/bycXcRVgg==} + /web-utility@4.1.0(typescript@5.1.6): + resolution: {integrity: sha512-3xH9M3F5nXcqXxlRqL24gv0+MewfOw/V1sSTOxXGuxYAxGz+IurDbZ4tsZZV/cZca4bPQEHqXcukfMLccNggkA==} peerDependencies: typescript: '>=4.1.0' dependencies: diff --git a/src/module/BITable.ts b/src/module/BITable.ts index ff66455..11d2061 100644 --- a/src/module/BITable.ts +++ b/src/module/BITable.ts @@ -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, @@ -170,7 +170,27 @@ export function BiTable() { this.baseURI = `bitable/v1/apps/${id}/tables`; } - tableMap = {} as Record>; + currentDataTable?: ListModel; + + async getOne( + tableName: string, + DataTableClass?: BiDataTableClass + ) { + 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} @@ -183,24 +203,6 @@ export function BiTable() { )) yield item; } - - async getAllTables< - T extends Record>> - >(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 = { - [K in keyof T]: T[K] extends Constructor ? M : never; - }; - return this.tableMap as UnwrapMap; - } } return BiTableModel; } diff --git a/src/type.ts b/src/type.ts index 301dd4a..b81b8da 100644 --- a/src/type.ts +++ b/src/type.ts @@ -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'; } @@ -161,6 +172,7 @@ export type TableCellValue = | string | number | boolean + | TableCellLocation | TableCellLink | ( | string