96 lines
1.8 KiB
TypeScript
96 lines
1.8 KiB
TypeScript
import { Query } from '../api.ts';
|
|
|
|
export type BaseOptions = {
|
|
query: Query;
|
|
};
|
|
|
|
export type BaseInfo = {
|
|
id?: string;
|
|
title: string;
|
|
description?: string;
|
|
config?: Record<string, any>;
|
|
color?: string;
|
|
meta?: Record<string, any>;
|
|
order?: number;
|
|
prefix?: string;
|
|
status?: string;
|
|
type?: string;
|
|
created_at?: string;
|
|
updated_at?: string;
|
|
};
|
|
|
|
export type CreateBaseData = {
|
|
title: string;
|
|
description?: string;
|
|
color?: string;
|
|
meta?: Record<string, any>;
|
|
config?: Record<string, any>;
|
|
};
|
|
|
|
export type UpdateBaseData = {
|
|
id?: string;
|
|
title?: string;
|
|
description?: string;
|
|
color?: string;
|
|
meta?: Record<string, any>;
|
|
config?: Record<string, any>;
|
|
};
|
|
|
|
export type BaseListResult = {
|
|
code: number;
|
|
list: BaseInfo[];
|
|
pageInfo?: {
|
|
totalRows?: number;
|
|
page?: number;
|
|
pageSize?: number;
|
|
isFirstPage?: boolean;
|
|
isLastPage?: boolean;
|
|
};
|
|
};
|
|
|
|
export type BaseResult = {
|
|
code: number;
|
|
data?: BaseInfo;
|
|
message?: string;
|
|
};
|
|
|
|
/**
|
|
* NocoDB Base 管理服务
|
|
* @url https://nocodb.com/apis/v2/meta
|
|
*/
|
|
export class MetaBases {
|
|
query: Query;
|
|
|
|
constructor(options?: BaseOptions) {
|
|
this.query = options?.query;
|
|
}
|
|
|
|
/**
|
|
* 列出所有 bases
|
|
*/
|
|
async list(workspaceId: string): Promise<BaseListResult> {
|
|
return this.query.makeRequest(`/api/v2/meta/workspaces/${workspaceId}/bases`, {
|
|
method: 'GET',
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 创建新的 base
|
|
*/
|
|
async create(data: CreateBaseData): Promise<BaseResult> {
|
|
return this.query.makeRequest('/api/v2/meta/bases', {
|
|
method: 'POST',
|
|
data,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 获取指定 base 的信息
|
|
*/
|
|
async get(baseId: string): Promise<BaseResult> {
|
|
return this.query.makeRequest(`/api/v2/meta/bases/${baseId}`, {
|
|
method: 'GET',
|
|
});
|
|
}
|
|
}
|