teable-api-sdk 1.0.0-test.1

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.
@@ -0,0 +1,232 @@
1
+ import z from "zod";
2
+ /**
3
+ * 创建记录请求验证模式
4
+ */
5
+ export declare const RecordCreateSchema: z.ZodObject<{
6
+ tableId: z.ZodString;
7
+ records: z.ZodArray<z.ZodObject<{
8
+ fields: z.ZodRecord<z.ZodString, z.ZodAny>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ fields: Record<string, any>;
11
+ }, {
12
+ fields: Record<string, any>;
13
+ }>, "many">;
14
+ fieldKeyType: z.ZodOptional<z.ZodEnum<["name", "id", "dbFieldName"]>>;
15
+ typecast: z.ZodOptional<z.ZodBoolean>;
16
+ order: z.ZodOptional<z.ZodObject<{
17
+ viewId: z.ZodString;
18
+ anchorId: z.ZodString;
19
+ position: z.ZodEnum<["before", "after"]>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ viewId: string;
22
+ anchorId: string;
23
+ position: "before" | "after";
24
+ }, {
25
+ viewId: string;
26
+ anchorId: string;
27
+ position: "before" | "after";
28
+ }>>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ tableId: string;
31
+ records: {
32
+ fields: Record<string, any>;
33
+ }[];
34
+ fieldKeyType?: "name" | "id" | "dbFieldName" | undefined;
35
+ typecast?: boolean | undefined;
36
+ order?: {
37
+ viewId: string;
38
+ anchorId: string;
39
+ position: "before" | "after";
40
+ } | undefined;
41
+ }, {
42
+ tableId: string;
43
+ records: {
44
+ fields: Record<string, any>;
45
+ }[];
46
+ fieldKeyType?: "name" | "id" | "dbFieldName" | undefined;
47
+ typecast?: boolean | undefined;
48
+ order?: {
49
+ viewId: string;
50
+ anchorId: string;
51
+ position: "before" | "after";
52
+ } | undefined;
53
+ }>;
54
+ /**
55
+ * 获取记录请求验证模式
56
+ */
57
+ export declare const RecordGetSchema: z.ZodObject<{
58
+ tableId: z.ZodString;
59
+ viewId: z.ZodOptional<z.ZodString>;
60
+ take: z.ZodOptional<z.ZodNumber>;
61
+ skip: z.ZodOptional<z.ZodNumber>;
62
+ fieldKeyType: z.ZodOptional<z.ZodEnum<["name", "id", "dbFieldName"]>>;
63
+ cellFormat: z.ZodOptional<z.ZodEnum<["json", "text"]>>;
64
+ projection: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
65
+ orderBy: z.ZodOptional<z.ZodArray<z.ZodObject<{
66
+ field: z.ZodString;
67
+ order: z.ZodEnum<["asc", "desc"]>;
68
+ }, "strip", z.ZodTypeAny, {
69
+ order: "asc" | "desc";
70
+ field: string;
71
+ }, {
72
+ order: "asc" | "desc";
73
+ field: string;
74
+ }>, "many">>;
75
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
76
+ search: z.ZodOptional<z.ZodArray<z.ZodObject<{
77
+ field: z.ZodString;
78
+ value: z.ZodString;
79
+ }, "strip", z.ZodTypeAny, {
80
+ value: string;
81
+ field: string;
82
+ }, {
83
+ value: string;
84
+ field: string;
85
+ }>, "many">>;
86
+ }, "strip", z.ZodTypeAny, {
87
+ tableId: string;
88
+ filter?: Record<string, any> | undefined;
89
+ fieldKeyType?: "name" | "id" | "dbFieldName" | undefined;
90
+ viewId?: string | undefined;
91
+ take?: number | undefined;
92
+ skip?: number | undefined;
93
+ cellFormat?: "json" | "text" | undefined;
94
+ projection?: string[] | undefined;
95
+ orderBy?: {
96
+ order: "asc" | "desc";
97
+ field: string;
98
+ }[] | undefined;
99
+ search?: {
100
+ value: string;
101
+ field: string;
102
+ }[] | undefined;
103
+ }, {
104
+ tableId: string;
105
+ filter?: Record<string, any> | undefined;
106
+ fieldKeyType?: "name" | "id" | "dbFieldName" | undefined;
107
+ viewId?: string | undefined;
108
+ take?: number | undefined;
109
+ skip?: number | undefined;
110
+ cellFormat?: "json" | "text" | undefined;
111
+ projection?: string[] | undefined;
112
+ orderBy?: {
113
+ order: "asc" | "desc";
114
+ field: string;
115
+ }[] | undefined;
116
+ search?: {
117
+ value: string;
118
+ field: string;
119
+ }[] | undefined;
120
+ }>;
121
+ /**
122
+ * 获取单个记录请求验证模式
123
+ */
124
+ export declare const RecordGetByIdSchema: z.ZodObject<{
125
+ tableId: z.ZodString;
126
+ recordId: z.ZodString;
127
+ projection: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
128
+ fieldKeyType: z.ZodOptional<z.ZodEnum<["name", "id", "dbFieldName"]>>;
129
+ cellFormat: z.ZodOptional<z.ZodEnum<["json", "text"]>>;
130
+ }, "strip", z.ZodTypeAny, {
131
+ tableId: string;
132
+ recordId: string;
133
+ fieldKeyType?: "name" | "id" | "dbFieldName" | undefined;
134
+ cellFormat?: "json" | "text" | undefined;
135
+ projection?: string[] | undefined;
136
+ }, {
137
+ tableId: string;
138
+ recordId: string;
139
+ fieldKeyType?: "name" | "id" | "dbFieldName" | undefined;
140
+ cellFormat?: "json" | "text" | undefined;
141
+ projection?: string[] | undefined;
142
+ }>;
143
+ /**
144
+ * 更新记录请求验证模式
145
+ */
146
+ export declare const RecordUpdateSchema: z.ZodObject<{
147
+ tableId: z.ZodString;
148
+ recordId: z.ZodString;
149
+ record: z.ZodObject<{
150
+ fields: z.ZodRecord<z.ZodString, z.ZodAny>;
151
+ }, "strip", z.ZodTypeAny, {
152
+ fields: Record<string, any>;
153
+ }, {
154
+ fields: Record<string, any>;
155
+ }>;
156
+ fieldKeyType: z.ZodOptional<z.ZodEnum<["name", "id", "dbFieldName"]>>;
157
+ typecast: z.ZodOptional<z.ZodBoolean>;
158
+ order: z.ZodOptional<z.ZodObject<{
159
+ viewId: z.ZodString;
160
+ anchorId: z.ZodString;
161
+ position: z.ZodEnum<["before", "after"]>;
162
+ }, "strip", z.ZodTypeAny, {
163
+ viewId: string;
164
+ anchorId: string;
165
+ position: "before" | "after";
166
+ }, {
167
+ viewId: string;
168
+ anchorId: string;
169
+ position: "before" | "after";
170
+ }>>;
171
+ }, "strip", z.ZodTypeAny, {
172
+ tableId: string;
173
+ recordId: string;
174
+ record: {
175
+ fields: Record<string, any>;
176
+ };
177
+ fieldKeyType?: "name" | "id" | "dbFieldName" | undefined;
178
+ typecast?: boolean | undefined;
179
+ order?: {
180
+ viewId: string;
181
+ anchorId: string;
182
+ position: "before" | "after";
183
+ } | undefined;
184
+ }, {
185
+ tableId: string;
186
+ recordId: string;
187
+ record: {
188
+ fields: Record<string, any>;
189
+ };
190
+ fieldKeyType?: "name" | "id" | "dbFieldName" | undefined;
191
+ typecast?: boolean | undefined;
192
+ order?: {
193
+ viewId: string;
194
+ anchorId: string;
195
+ position: "before" | "after";
196
+ } | undefined;
197
+ }>;
198
+ /**
199
+ * 删除记录请求验证模式
200
+ */
201
+ export declare const RecordDeleteSchema: z.ZodObject<{
202
+ tableId: z.ZodString;
203
+ recordId: z.ZodString;
204
+ }, "strip", z.ZodTypeAny, {
205
+ tableId: string;
206
+ recordId: string;
207
+ }, {
208
+ tableId: string;
209
+ recordId: string;
210
+ }>;
211
+ /**
212
+ * 上传附件请求验证模式
213
+ */
214
+ export declare const RecordUploadAttachmentSchema: z.ZodObject<{
215
+ tableId: z.ZodString;
216
+ recordId: z.ZodString;
217
+ fieldId: z.ZodString;
218
+ file: z.ZodType<File, z.ZodTypeDef, File>;
219
+ fileUrl: z.ZodOptional<z.ZodString>;
220
+ }, "strip", z.ZodTypeAny, {
221
+ tableId: string;
222
+ recordId: string;
223
+ fieldId: string;
224
+ file: File;
225
+ fileUrl?: string | undefined;
226
+ }, {
227
+ tableId: string;
228
+ recordId: string;
229
+ fieldId: string;
230
+ file: File;
231
+ fileUrl?: string | undefined;
232
+ }>;
@@ -0,0 +1,262 @@
1
+ import { FieldKeyType, RecordOrder, CellFormat, SortObject, SearchCondition, TableRecord } from "../types";
2
+ export * from "../types";
3
+ /**
4
+ * 创建记录选项
5
+ */
6
+ export interface RecordCreateOptions {
7
+ /** 表 ID */
8
+ tableId: string;
9
+ /** 要创建的记录数组 */
10
+ records: Array<{
11
+ /** 字段数据,每个字段的值结构根据字段类型而不同 */
12
+ fields: Record<string, any>;
13
+ }>;
14
+ /**
15
+ * 字段键类型(可选)
16
+ * @default "name"
17
+ */
18
+ fieldKeyType?: FieldKeyType;
19
+ /**
20
+ * 是否自动转换字段值类型(可选)
21
+ * 如果设置为 true,系统会尝试将输入值转换为正确的字段值类型
22
+ * @default false
23
+ */
24
+ typecast?: boolean;
25
+ /**
26
+ * 记录排序配置(可选)
27
+ * 指定新记录在指定视图中的位置
28
+ */
29
+ order?: RecordOrder;
30
+ }
31
+ /**
32
+ * 创建记录响应
33
+ */
34
+ export interface RecordCreateResponse {
35
+ /** 创建的记录数组 */
36
+ records: TableRecord[];
37
+ }
38
+ /**
39
+ * 获取记录选项
40
+ */
41
+ export interface RecordGetOptions {
42
+ /** 表 ID */
43
+ tableId: string;
44
+ /**
45
+ * 视图 ID(可选)
46
+ * 如果未指定,会按照创建时间来返回记录的顺序,并且返回所有记录和字段
47
+ */
48
+ viewId?: string;
49
+ /**
50
+ * 获取的记录数量(可选)
51
+ * @default undefined
52
+ * @maximum 1000
53
+ */
54
+ take?: number;
55
+ /**
56
+ * 跳过的记录数量(可选)
57
+ * 用于分页
58
+ * @default undefined
59
+ */
60
+ skip?: number;
61
+ /**
62
+ * 字段键类型(可选)
63
+ * @default "name"
64
+ */
65
+ fieldKeyType?: FieldKeyType;
66
+ /**
67
+ * 单元格返回值格式(可选)
68
+ * @default "json"
69
+ */
70
+ cellFormat?: CellFormat;
71
+ /**
72
+ * 指定要获取的字段(可选)
73
+ * 如果不指定,将获取所有可见字段
74
+ * 参数值取决于 fieldKeyType 设置
75
+ */
76
+ projection?: string[];
77
+ /**
78
+ * 排序方式(可选)
79
+ * 排序对象数组
80
+ */
81
+ orderBy?: SortObject[];
82
+ /**
83
+ * 筛选条件(可选)
84
+ * 用于筛选结果的复杂查询条件对象
85
+ */
86
+ filter?: Record<string, any>;
87
+ /**
88
+ * 搜索条件(可选)
89
+ * 搜索匹配指定字段和值的记录
90
+ */
91
+ search?: SearchCondition[];
92
+ }
93
+ /**
94
+ * 获取记录响应
95
+ */
96
+ export interface RecordGetResponse {
97
+ /** 记录数组 */
98
+ records: TableRecord[];
99
+ /** 偏移量(用于分页) */
100
+ offset?: string;
101
+ }
102
+ /**
103
+ * 获取单个记录选项
104
+ */
105
+ export interface RecordGetByIdOptions {
106
+ /** 表 ID */
107
+ tableId: string;
108
+ /** 记录 ID */
109
+ recordId: string;
110
+ /**
111
+ * 指定要获取的字段(可选)
112
+ * 如果不指定,将获取所有可见字段
113
+ * 参数值取决于 fieldKeyType 设置
114
+ */
115
+ projection?: string[];
116
+ /**
117
+ * 单元格返回值格式(可选)
118
+ * @default "json"
119
+ */
120
+ cellFormat?: CellFormat;
121
+ /**
122
+ * 字段键类型(可选)
123
+ * @default "name"
124
+ */
125
+ fieldKeyType?: FieldKeyType;
126
+ }
127
+ /**
128
+ * 获取单个记录响应
129
+ */
130
+ export interface RecordGetByIdResponse {
131
+ /** 记录 ID */
132
+ id: string;
133
+ /** 字段数据 */
134
+ fields: Record<string, any>;
135
+ /** 主字段值 */
136
+ name: string;
137
+ /** 自增编号 */
138
+ autoNumber: number;
139
+ /** 创建时间 */
140
+ createdTime: string;
141
+ /** 最后修改时间 */
142
+ lastModifiedTime: string;
143
+ /** 创建者 */
144
+ createdBy: string;
145
+ /** 最后修改者 */
146
+ lastModifiedBy: string;
147
+ /** 权限信息 */
148
+ permissions: Record<string, any>;
149
+ /** 是否不可删除 */
150
+ undeletable: boolean;
151
+ }
152
+ /**
153
+ * 更新记录选项
154
+ */
155
+ export interface RecordUpdateOptions {
156
+ /** 表 ID */
157
+ tableId: string;
158
+ /** 记录 ID */
159
+ recordId: string;
160
+ /** 记录数据 */
161
+ record: {
162
+ /** 字段数据,每个字段的值结构根据字段类型而不同 */
163
+ fields: Record<string, any>;
164
+ };
165
+ /**
166
+ * 字段键类型(可选)
167
+ * @default "name"
168
+ */
169
+ fieldKeyType?: FieldKeyType;
170
+ /**
171
+ * 是否自动转换字段值类型(可选)
172
+ * 如果设置为 true,系统会尝试将输入值转换为正确的字段值类型
173
+ * @default false
174
+ */
175
+ typecast?: boolean;
176
+ /**
177
+ * 记录排序配置(可选)
178
+ * 指定新记录在指定视图中的位置
179
+ */
180
+ order?: RecordOrder;
181
+ }
182
+ /**
183
+ * 更新记录响应
184
+ */
185
+ export interface RecordUpdateResponse {
186
+ /** 记录 ID */
187
+ id: string;
188
+ /** 字段数据 */
189
+ fields: Record<string, any>;
190
+ /** 主字段值 */
191
+ name: string;
192
+ /** 自增编号 */
193
+ autoNumber: number;
194
+ /** 创建时间 */
195
+ createdTime: string;
196
+ /** 最后修改时间 */
197
+ lastModifiedTime: string;
198
+ /** 创建者 */
199
+ createdBy: string;
200
+ /** 最后修改者 */
201
+ lastModifiedBy: string;
202
+ /** 权限信息 */
203
+ permissions: Record<string, any>;
204
+ /** 是否不可删除 */
205
+ undeletable: boolean;
206
+ }
207
+ /**
208
+ * 删除记录选项
209
+ */
210
+ export interface RecordDeleteOptions {
211
+ /** 表 ID */
212
+ tableId: string;
213
+ /** 记录 ID */
214
+ recordId: string;
215
+ }
216
+ /**
217
+ * 删除记录响应
218
+ */
219
+ export interface RecordDeleteResponse {
220
+ /** 是否删除成功 */
221
+ success: boolean;
222
+ }
223
+ /**
224
+ * 上传附件选项
225
+ */
226
+ export interface RecordUploadAttachmentOptions {
227
+ /** 表 ID */
228
+ tableId: string;
229
+ /** 记录 ID */
230
+ recordId: string;
231
+ /** 附件字段 ID */
232
+ fieldId: string;
233
+ /** 要上传的文件 */
234
+ file: File;
235
+ /** 文件 URL(可选,作为 file 的替代) */
236
+ fileUrl?: string;
237
+ }
238
+ /**
239
+ * 上传附件响应
240
+ */
241
+ export interface RecordUploadAttachmentResponse {
242
+ /** 记录 ID */
243
+ id: string;
244
+ /** 字段数据 */
245
+ fields: Record<string, any>;
246
+ /** 主字段值 */
247
+ name: string;
248
+ /** 自增编号 */
249
+ autoNumber: number;
250
+ /** 创建时间 */
251
+ createdTime: string;
252
+ /** 最后修改时间 */
253
+ lastModifiedTime: string;
254
+ /** 创建者 */
255
+ createdBy: string;
256
+ /** 最后修改者 */
257
+ lastModifiedBy: string;
258
+ /** 权限信息 */
259
+ permissions: Record<string, any>;
260
+ /** 是否不可删除 */
261
+ undeletable: boolean;
262
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Teable SDK 配置
3
+ */
4
+ export interface TeableConfig {
5
+ /** API 密钥 */
6
+ apiKey: string;
7
+ /** Teable 服务器基础 URL */
8
+ baseUrl: string;
9
+ /** 数据库 ID(可选) */
10
+ databaseId?: string;
11
+ /** 日记表 ID(可选) */
12
+ diaryTableId?: string;
13
+ }
14
+ /**
15
+ * 表记录
16
+ */
17
+ export interface TableRecord {
18
+ /** 记录 ID */
19
+ id?: string;
20
+ /** 字段数据 */
21
+ fields: Record<string, any>;
22
+ /** 创建时间 */
23
+ createdTime?: string;
24
+ /** 更新时间 */
25
+ updatedTime?: string;
26
+ }
27
+ /**
28
+ * 字段键类型
29
+ * - "name": 使用字段名作为键
30
+ * - "id": 使用字段 ID 作为键
31
+ * - "dbFieldName": 使用字段 dbFieldName 作为键
32
+ */
33
+ export type FieldKeyType = "name" | "id" | "dbFieldName";
34
+ /**
35
+ * 记录排序位置
36
+ * - "before": 在锚点记录之前
37
+ * - "after": 在锚点记录之后
38
+ */
39
+ export type RecordPosition = "before" | "after";
40
+ /**
41
+ * 记录排序配置
42
+ */
43
+ export interface RecordOrder {
44
+ /** 视图 ID */
45
+ viewId: string;
46
+ /** 锚点记录 ID */
47
+ anchorId: string;
48
+ /** 相对于锚点记录的位置 */
49
+ position: RecordPosition;
50
+ }
51
+ /**
52
+ * 单元格格式
53
+ * - "json": 返回结构化的 JSON 数据(默认)
54
+ * - "text": 返回纯文本格式
55
+ */
56
+ export type CellFormat = "json" | "text";
57
+ /**
58
+ * 排序对象
59
+ */
60
+ export interface SortObject {
61
+ /** 字段名称或 ID(取决于 fieldKeyType) */
62
+ fieldId: string;
63
+ /** 排序方向 */
64
+ order: "asc" | "desc";
65
+ }
66
+ /**
67
+ * 搜索条件
68
+ */
69
+ export interface SearchCondition {
70
+ /** 字段名称或 ID(取决于 fieldKeyType) */
71
+ field: string;
72
+ /** 搜索值 */
73
+ value: string;
74
+ }
75
+ /**
76
+ * Teable API 响应
77
+ */
78
+ export interface TeableResponse<T = any> {
79
+ /** 操作是否成功 */
80
+ success: boolean;
81
+ /** 响应数据 */
82
+ data?: T;
83
+ /** 错误信息 */
84
+ error?: string;
85
+ /** 消息 */
86
+ message?: string;
87
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "teable-api-sdk",
3
+ "version": "1.0.0-test.1",
4
+ "description": "Teable API SDK - A TypeScript client for Teable API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "rollup -c",
13
+ "dev": "rollup -c -w",
14
+ "type-check": "tsc --noEmit",
15
+ "lint": "eslint src --ext .ts,.tsx",
16
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
17
+ "test": "jest",
18
+ "clean": "rm -rf dist",
19
+ "prepare": "npm run build",
20
+ "prepublishOnly": "npm run clean && npm run build"
21
+ },
22
+ "keywords": [
23
+ "teable",
24
+ "api",
25
+ "sdk",
26
+ "typescript",
27
+ "database",
28
+ "spreadsheet"
29
+ ],
30
+ "author": "Truraly",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/Truraly/teable-api-sdk.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/Truraly/teable-api-sdk/issues"
38
+ },
39
+ "homepage": "https://github.com/Truraly/teable-api-sdk#readme",
40
+ "peerDependencies": {
41
+ "axios": ">=1.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@rollup/plugin-commonjs": "^25.0.0",
45
+ "@rollup/plugin-json": "^6.0.0",
46
+ "@rollup/plugin-node-resolve": "^15.0.0",
47
+ "@rollup/plugin-typescript": "^11.0.0",
48
+ "@types/jest": "^29.0.0",
49
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
50
+ "@typescript-eslint/parser": "^6.0.0",
51
+ "eslint": "^8.0.0",
52
+ "jest": "^29.0.0",
53
+ "rollup": "^4.0.0",
54
+ "ts-jest": "^29.0.0",
55
+ "tslib": "^2.0.0",
56
+ "typescript": "^5.0.0"
57
+ },
58
+ "dependencies": {
59
+ "zod": "^3.22.0"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public",
63
+ "registry": "https://registry.npmjs.org/"
64
+ }
65
+ }