From a4e0ca9a8d50d6424f1be6cc3f83931fc965b13d Mon Sep 17 00:00:00 2001 From: abearxiong Date: Tue, 16 Dec 2025 22:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=B1=BB=E5=9E=8B=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=EF=BC=8C=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96=E8=A1=A8?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api.ts | 5 +++++ src/record.ts | 44 ++++++++++++++++++++++++++++++++++++++++---- test/list-table.ts | 2 +- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/api.ts b/src/api.ts index 49b42b3..237f523 100644 --- a/src/api.ts +++ b/src/api.ts @@ -92,4 +92,9 @@ export type ResponseList = { isLastPage?: boolean; }; } +}; + +export type Result = { + code: number; + data: T; }; \ No newline at end of file diff --git a/src/record.ts b/src/record.ts index 5fde556..898c6e7 100644 --- a/src/record.ts +++ b/src/record.ts @@ -1,6 +1,7 @@ -import { Query } from './api.ts'; +import { Query, Result } from './api.ts'; import { Meta } from './meta/index.ts'; + /** * https://nocodb.com/docs/product-docs/developer-resources/rest-apis#v3-where-query-parameter */ @@ -36,6 +37,7 @@ type ResultList = { } }; type Id = string | number; +const stystemFields = ['nc_order', 'nc_created_by', 'nc_updated_by'] /** * @url https://nocodb.com/apis/v2/data#tag/Table-Records */ @@ -102,11 +104,11 @@ export class Record { getTableMeta() { return this.meta.tables.getTableMeta(this.table); } - async getTableSchema() { + async getTableSchema(): Promise> { const res = await this.getTableMeta(); if (res.code === 200) { const columns = res.data.columns; - return columns.map(col => ({ + const _columns = columns.filter(col => !stystemFields.includes(col.title)).map(col => ({ id: col.id, name: col.title, type: col.uidt, @@ -114,9 +116,43 @@ export class Record { primary: col.pv, options: col.colOptions, })); + const schema: Schema = {}; + for (const col of _columns) { + schema[col.name] = { + type: col.type, + required: col.required, + options: col.options, + }; + } + return { + code: 200, + data: { + columns: _columns, + schema, + } + }; } - return []; + return res as { + code: number; data: { + columns: any[]; schema: Schema + } + }; } } +export type Schema = { + [key: string]: any; +} & T; +export type TableSchema = { + columns: { + id: string; + name: string; + type: string; + required: boolean; + primary: boolean; + options: any; + }[]; + schema: Schema; +} + diff --git a/test/list-table.ts b/test/list-table.ts index 7e39fa3..e604b8e 100644 --- a/test/list-table.ts +++ b/test/list-table.ts @@ -10,4 +10,4 @@ import { writeFileSync } from 'node:fs'; // writeFileSync('table-metadata.json', JSON.stringify(res, null, 2)); const res2 = await nocoApi.record.getTableSchema() -console.log(util.inspect(res2, { depth: null, colors: true })) \ No newline at end of file +console.log(util.inspect(res2.data.schema, { depth: null, colors: true })) \ No newline at end of file