apaas-oapi-client 0.1.35 → 0.1.37
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.
- package/.vscode/settings.json +9 -0
- package/README.md +67 -5
- package/UserManual.md +6 -5
- package/dist/field-schema-rules.d.ts +35 -0
- package/dist/field-types.d.ts +313 -0
- package/dist/index.d.ts +313 -19
- package/dist/index.js +866 -5
- package/package.json +4 -5
- package/src/FIELD_SCHEMA_RULES.md +81 -0
- package/src/field-schema-rules.ts +336 -0
- package/src/field-types.ts +867 -0
- package/src/index.ts +312 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
import { LoggerLevel } from './logger';
|
|
2
|
+
import { FIELD_TYPES, SYSTEM_FIELDS, LANGUAGE_CODES, SCHEMA_GUIDELINES, CREATE_OBJECT_EXAMPLE, UPDATE_OBJECT_ADD_FIELD_EXAMPLE, UPDATE_OBJECT_REPLACE_FIELD_EXAMPLE, UPDATE_OBJECT_REMOVE_FIELD_EXAMPLE, UPDATE_OBJECT_SETTINGS_EXAMPLE, getSystemFields, getCustomFieldTypes, getFieldType, isSystemField, createMultilingualText, extractMultilingualText, type FieldTypeMetadata, type MultilingualText, type ObjectSettings, type FieldTypeDefinition, type EncryptType, type FieldOperator, type CreateFieldDefinition, type UpdateFieldDefinition, type CreateObjectDefinition, type UpdateObjectDefinition } from './field-types';
|
|
3
|
+
/**
|
|
4
|
+
* 批量操作结果
|
|
5
|
+
*/
|
|
6
|
+
interface BatchResult<T> {
|
|
7
|
+
/** 成功的项 */
|
|
8
|
+
success: T[];
|
|
9
|
+
/** 失败的项 */
|
|
10
|
+
failed: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
error: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** 成功数量 */
|
|
15
|
+
successCount: number;
|
|
16
|
+
/** 失败数量 */
|
|
17
|
+
failedCount: number;
|
|
18
|
+
/** 总数 */
|
|
19
|
+
total: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 重试配置
|
|
23
|
+
*/
|
|
24
|
+
interface RetryOptions {
|
|
25
|
+
/** 最大重试次数 */
|
|
26
|
+
maxRetries?: number;
|
|
27
|
+
/** 初始延迟时间(ms) */
|
|
28
|
+
initialDelay?: number;
|
|
29
|
+
/** 最大延迟时间(ms) */
|
|
30
|
+
maxDelay?: number;
|
|
31
|
+
/** 延迟倍数 */
|
|
32
|
+
backoffMultiplier?: number;
|
|
33
|
+
}
|
|
2
34
|
/**
|
|
3
35
|
* Client 初始化配置
|
|
4
36
|
*/
|
|
@@ -71,17 +103,41 @@ declare class Client {
|
|
|
71
103
|
object: {
|
|
72
104
|
/**
|
|
73
105
|
* 列出所有对象(数据表)
|
|
74
|
-
* @param params 请求参数 { offset
|
|
75
|
-
* @returns 接口返回结果
|
|
106
|
+
* @param params 请求参数 { offset?, filter?, limit? }
|
|
107
|
+
* @returns 接口返回结果 { code, items, total, msg, has_more }
|
|
76
108
|
*/
|
|
77
|
-
list: (params
|
|
78
|
-
offset
|
|
109
|
+
list: (params?: {
|
|
110
|
+
offset?: number;
|
|
79
111
|
filter?: {
|
|
80
112
|
type?: string;
|
|
81
113
|
quickQuery?: string;
|
|
82
114
|
};
|
|
83
|
-
limit
|
|
115
|
+
limit?: number;
|
|
84
116
|
}) => Promise<any>;
|
|
117
|
+
/**
|
|
118
|
+
* 列出所有对象(数据表)- 支持自动分页查询
|
|
119
|
+
* @description 该方法会自动处理分页,直到没有更多数据为止
|
|
120
|
+
* @param params 请求参数 { filter?, limit? }
|
|
121
|
+
* @returns { code, msg, items, total, failed? } - code 表示失败的分页数量
|
|
122
|
+
*/
|
|
123
|
+
listWithIterator: (params?: {
|
|
124
|
+
filter?: {
|
|
125
|
+
type?: string;
|
|
126
|
+
quickQuery?: string;
|
|
127
|
+
};
|
|
128
|
+
limit?: number;
|
|
129
|
+
}) => Promise<{
|
|
130
|
+
code: string;
|
|
131
|
+
msg: string;
|
|
132
|
+
items: any[];
|
|
133
|
+
total: number;
|
|
134
|
+
failed?: Array<{
|
|
135
|
+
offset: number;
|
|
136
|
+
limit: number;
|
|
137
|
+
code: string;
|
|
138
|
+
msg: string;
|
|
139
|
+
}>;
|
|
140
|
+
}>;
|
|
85
141
|
metadata: {
|
|
86
142
|
/**
|
|
87
143
|
* 获取指定对象下指定字段的元数据
|
|
@@ -102,6 +158,36 @@ declare class Client {
|
|
|
102
158
|
fields: (params: {
|
|
103
159
|
object_name: string;
|
|
104
160
|
}) => Promise<any>;
|
|
161
|
+
/**
|
|
162
|
+
* 导出数据对象元数据为 Markdown 文档
|
|
163
|
+
* @description 将数据对象的字段信息导出为详细的 Markdown 文档,包含字段类型、配置、选项等完整信息
|
|
164
|
+
* @param options 导出配置
|
|
165
|
+
* @param options.object_names 可选,要导出的对象名称数组。如果不传,则导出所有对象
|
|
166
|
+
* @returns Markdown 文档字符串
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // 导出所有对象
|
|
170
|
+
* const markdown = await client.object.metadata.export2markdown();
|
|
171
|
+
*
|
|
172
|
+
* // 只导出指定对象
|
|
173
|
+
* const markdown = await client.object.metadata.export2markdown({
|
|
174
|
+
* object_names: ['object_store', 'object_order', '_user']
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* // 结合 listWithIterator 使用
|
|
178
|
+
* const allObjects = await client.object.listWithIterator();
|
|
179
|
+
* const objectNames = allObjects.items.map(obj => obj.apiName);
|
|
180
|
+
* const markdown = await client.object.metadata.export2markdown({
|
|
181
|
+
* object_names: objectNames
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
* // 保存到文件
|
|
185
|
+
* fs.writeFileSync('objects_doc.md', markdown, 'utf-8');
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export2markdown: (options?: {
|
|
189
|
+
object_names?: string[];
|
|
190
|
+
}) => Promise<string>;
|
|
105
191
|
};
|
|
106
192
|
search: {
|
|
107
193
|
/**
|
|
@@ -138,6 +224,16 @@ declare class Client {
|
|
|
138
224
|
total: number;
|
|
139
225
|
items: any[];
|
|
140
226
|
}>;
|
|
227
|
+
/**
|
|
228
|
+
* 统计记录数量
|
|
229
|
+
* @description 统计指定对象中的记录总数,支持按条件统计
|
|
230
|
+
* @param params 请求参数 { object_name, data? }
|
|
231
|
+
* @returns 接口返回结果 { code, total, msg }
|
|
232
|
+
*/
|
|
233
|
+
count: (params: {
|
|
234
|
+
object_name: string;
|
|
235
|
+
data?: any;
|
|
236
|
+
}) => Promise<any>;
|
|
141
237
|
};
|
|
142
238
|
create: {
|
|
143
239
|
/**
|
|
@@ -163,15 +259,26 @@ declare class Client {
|
|
|
163
259
|
/**
|
|
164
260
|
* 分批创建所有记录 - 支持超过 100 条数据,自动拆分
|
|
165
261
|
* @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
|
|
166
|
-
* @param params 请求参数 { object_name, records }
|
|
167
|
-
* @returns { total,
|
|
262
|
+
* @param params 请求参数 { object_name, records, limit }
|
|
263
|
+
* @returns { total, success, failed, successCount, failedCount }
|
|
168
264
|
*/
|
|
169
265
|
recordsWithIterator: (params: {
|
|
170
266
|
object_name: string;
|
|
171
267
|
records: any[];
|
|
268
|
+
limit?: number;
|
|
172
269
|
}) => Promise<{
|
|
173
270
|
total: number;
|
|
174
|
-
|
|
271
|
+
success: Array<{
|
|
272
|
+
_id: string;
|
|
273
|
+
success: true;
|
|
274
|
+
}>;
|
|
275
|
+
failed: Array<{
|
|
276
|
+
_id: string;
|
|
277
|
+
success: false;
|
|
278
|
+
error?: string;
|
|
279
|
+
}>;
|
|
280
|
+
successCount: number;
|
|
281
|
+
failedCount: number;
|
|
175
282
|
}>;
|
|
176
283
|
};
|
|
177
284
|
update: {
|
|
@@ -199,19 +306,33 @@ declare class Client {
|
|
|
199
306
|
/**
|
|
200
307
|
* 批量更新 - 支持超过 100 条数据,自动拆分
|
|
201
308
|
* @description 更新指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
|
|
202
|
-
* @param params
|
|
203
|
-
* @returns
|
|
309
|
+
* @param params 请求参数,包含 object_name, records, limit
|
|
310
|
+
* @returns { total, success, failed, successCount, failedCount }
|
|
204
311
|
*/
|
|
205
312
|
recordsWithIterator: (params: {
|
|
206
313
|
object_name: string;
|
|
207
314
|
records: any[];
|
|
208
|
-
|
|
315
|
+
limit?: number;
|
|
316
|
+
}) => Promise<{
|
|
317
|
+
total: number;
|
|
318
|
+
success: Array<{
|
|
319
|
+
_id: string;
|
|
320
|
+
success: true;
|
|
321
|
+
}>;
|
|
322
|
+
failed: Array<{
|
|
323
|
+
_id: string;
|
|
324
|
+
success: false;
|
|
325
|
+
error?: string;
|
|
326
|
+
}>;
|
|
327
|
+
successCount: number;
|
|
328
|
+
failedCount: number;
|
|
329
|
+
}>;
|
|
209
330
|
};
|
|
210
331
|
delete: {
|
|
211
332
|
/**
|
|
212
333
|
* 单条删除
|
|
213
334
|
* @description 删除指定对象下的单条记录
|
|
214
|
-
* @param params
|
|
335
|
+
* @param params 请求参数,包含 object_name 和 record_id
|
|
215
336
|
* @returns 接口返回结果
|
|
216
337
|
*/
|
|
217
338
|
record: (params: {
|
|
@@ -221,7 +342,7 @@ declare class Client {
|
|
|
221
342
|
/**
|
|
222
343
|
* 多条删除 - 最多传入 100 条
|
|
223
344
|
* @description 删除指定对象下的多条记录
|
|
224
|
-
* @param params
|
|
345
|
+
* @param params 请求参数,包含 object_name 和 ids 数组
|
|
225
346
|
* @returns 接口返回结果
|
|
226
347
|
*/
|
|
227
348
|
records: (params: {
|
|
@@ -231,13 +352,27 @@ declare class Client {
|
|
|
231
352
|
/**
|
|
232
353
|
* 批量删除
|
|
233
354
|
* @description 删除指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
|
|
234
|
-
* @param params
|
|
235
|
-
* @returns
|
|
355
|
+
* @param params 请求参数,包含 object_name, ids 数组 和 可选的 limit
|
|
356
|
+
* @returns { total, success, failed, successCount, failedCount }
|
|
236
357
|
*/
|
|
237
358
|
recordsWithIterator: (params: {
|
|
238
359
|
object_name: string;
|
|
239
360
|
ids: string[];
|
|
240
|
-
|
|
361
|
+
limit?: number;
|
|
362
|
+
}) => Promise<{
|
|
363
|
+
total: number;
|
|
364
|
+
success: Array<{
|
|
365
|
+
_id: string;
|
|
366
|
+
success: true;
|
|
367
|
+
}>;
|
|
368
|
+
failed: Array<{
|
|
369
|
+
_id: string;
|
|
370
|
+
success: false;
|
|
371
|
+
error?: string;
|
|
372
|
+
}>;
|
|
373
|
+
successCount: number;
|
|
374
|
+
failedCount: number;
|
|
375
|
+
}>;
|
|
241
376
|
};
|
|
242
377
|
};
|
|
243
378
|
/**
|
|
@@ -256,12 +391,39 @@ declare class Client {
|
|
|
256
391
|
/**
|
|
257
392
|
* 批量部门 ID 交换
|
|
258
393
|
* @param params 请求参数
|
|
259
|
-
* @returns
|
|
394
|
+
* @returns 批量操作结果,包含成功和失败的详细信息
|
|
260
395
|
*/
|
|
261
396
|
batchExchange: (params: {
|
|
262
397
|
department_id_type: "department_id" | "external_department_id" | "external_open_department_id";
|
|
263
398
|
department_ids: string[];
|
|
264
|
-
|
|
399
|
+
retryOptions?: RetryOptions;
|
|
400
|
+
}) => Promise<BatchResult<any>>;
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* 用户 ID 交换模块
|
|
404
|
+
*/
|
|
405
|
+
user: {
|
|
406
|
+
/**
|
|
407
|
+
* 单个用户 ID 交换
|
|
408
|
+
* @param params 请求参数
|
|
409
|
+
* @returns 单个用户映射结果
|
|
410
|
+
*/
|
|
411
|
+
exchange: (params: {
|
|
412
|
+
user_id_type: "user_id" | "external_user_id" | "external_open_id";
|
|
413
|
+
user_id: string;
|
|
414
|
+
feishu_app_id: string;
|
|
415
|
+
}) => Promise<any>;
|
|
416
|
+
/**
|
|
417
|
+
* 批量用户 ID 交换
|
|
418
|
+
* @param params 请求参数
|
|
419
|
+
* @returns 批量操作结果,包含成功和失败的详细信息
|
|
420
|
+
*/
|
|
421
|
+
batchExchange: (params: {
|
|
422
|
+
user_id_type: "user_id" | "external_user_id" | "external_open_id";
|
|
423
|
+
user_ids: string[];
|
|
424
|
+
feishu_app_id: string;
|
|
425
|
+
retryOptions?: RetryOptions;
|
|
426
|
+
}) => Promise<BatchResult<any>>;
|
|
265
427
|
};
|
|
266
428
|
/**
|
|
267
429
|
* 云函数模块
|
|
@@ -506,8 +668,140 @@ declare class Client {
|
|
|
506
668
|
}) => Promise<any>;
|
|
507
669
|
};
|
|
508
670
|
};
|
|
671
|
+
/**
|
|
672
|
+
* 数据对象结构管理模块(Schema)
|
|
673
|
+
*/
|
|
674
|
+
schema: {
|
|
675
|
+
/**
|
|
676
|
+
* 批量创建数据对象(表)
|
|
677
|
+
* @description 批量创建一个或多个数据对象
|
|
678
|
+
* @param params 请求参数 { objects: Array }
|
|
679
|
+
* @returns 接口返回结果
|
|
680
|
+
*/
|
|
681
|
+
create: (params: {
|
|
682
|
+
objects: Array<{
|
|
683
|
+
api_name: string;
|
|
684
|
+
label: {
|
|
685
|
+
zh_cn: string;
|
|
686
|
+
en_us: string;
|
|
687
|
+
};
|
|
688
|
+
settings?: {
|
|
689
|
+
allow_search_fields?: string[];
|
|
690
|
+
display_name?: string;
|
|
691
|
+
search_layout?: string[];
|
|
692
|
+
};
|
|
693
|
+
fields: Array<{
|
|
694
|
+
api_name: string;
|
|
695
|
+
label: {
|
|
696
|
+
zh_cn: string;
|
|
697
|
+
en_us: string;
|
|
698
|
+
};
|
|
699
|
+
type: {
|
|
700
|
+
name: string;
|
|
701
|
+
settings?: any;
|
|
702
|
+
};
|
|
703
|
+
encrypt_type?: string | null;
|
|
704
|
+
}>;
|
|
705
|
+
}>;
|
|
706
|
+
}) => Promise<any>;
|
|
707
|
+
/**
|
|
708
|
+
* 批量更新数据对象(表)
|
|
709
|
+
* @description 批量更新一个或多个数据对象的配置
|
|
710
|
+
* @param params 请求参数 { objects: Array }
|
|
711
|
+
* @returns 接口返回结果
|
|
712
|
+
* @example
|
|
713
|
+
* ```typescript
|
|
714
|
+
* // 添加新字段
|
|
715
|
+
* await client.schema.update({
|
|
716
|
+
* objects: [{
|
|
717
|
+
* api_name: 'my_object',
|
|
718
|
+
* fields: [{
|
|
719
|
+
* operator: 'add',
|
|
720
|
+
* api_name: 'new_field',
|
|
721
|
+
* label: { zh_cn: '新字段', en_us: 'New Field' },
|
|
722
|
+
* type: { name: 'text', settings: { required: false } },
|
|
723
|
+
* encrypt_type: 'none'
|
|
724
|
+
* }]
|
|
725
|
+
* }]
|
|
726
|
+
* });
|
|
727
|
+
*
|
|
728
|
+
* // 修改现有字段
|
|
729
|
+
* await client.schema.update({
|
|
730
|
+
* objects: [{
|
|
731
|
+
* api_name: 'my_object',
|
|
732
|
+
* fields: [{
|
|
733
|
+
* operator: 'replace',
|
|
734
|
+
* api_name: 'existing_field',
|
|
735
|
+
* label: { zh_cn: '新标签', en_us: 'New Label' }
|
|
736
|
+
* }]
|
|
737
|
+
* }]
|
|
738
|
+
* });
|
|
739
|
+
*
|
|
740
|
+
* // 删除字段
|
|
741
|
+
* await client.schema.update({
|
|
742
|
+
* objects: [{
|
|
743
|
+
* api_name: 'my_object',
|
|
744
|
+
* fields: [{
|
|
745
|
+
* operator: 'remove',
|
|
746
|
+
* api_name: 'field_to_delete'
|
|
747
|
+
* }]
|
|
748
|
+
* }]
|
|
749
|
+
* });
|
|
750
|
+
* ```
|
|
751
|
+
*/
|
|
752
|
+
update: (params: {
|
|
753
|
+
objects: Array<{
|
|
754
|
+
api_name: string;
|
|
755
|
+
label?: {
|
|
756
|
+
zh_cn: string;
|
|
757
|
+
en_us: string;
|
|
758
|
+
};
|
|
759
|
+
settings?: {
|
|
760
|
+
allow_search_fields?: string[];
|
|
761
|
+
display_name?: string;
|
|
762
|
+
search_layout?: string[];
|
|
763
|
+
};
|
|
764
|
+
fields?: Array<{
|
|
765
|
+
/** 操作类型:add=添加字段, replace=修改字段, remove=删除字段 */
|
|
766
|
+
operator: "add" | "replace" | "remove";
|
|
767
|
+
/** 字段 API 名称 */
|
|
768
|
+
api_name: string;
|
|
769
|
+
/** 字段标签(可选,operator=add 和 replace 时使用) */
|
|
770
|
+
label?: {
|
|
771
|
+
zh_cn: string;
|
|
772
|
+
en_us: string;
|
|
773
|
+
};
|
|
774
|
+
/** 字段类型(可选,operator=add 和 replace 时使用) */
|
|
775
|
+
type?: {
|
|
776
|
+
name: string;
|
|
777
|
+
settings?: any;
|
|
778
|
+
};
|
|
779
|
+
/** 加密类型(可选) */
|
|
780
|
+
encrypt_type?: string | null;
|
|
781
|
+
}>;
|
|
782
|
+
}>;
|
|
783
|
+
}) => Promise<any>;
|
|
784
|
+
/**
|
|
785
|
+
* 批量删除数据对象(表)
|
|
786
|
+
* @description 批量删除一个或多个数据对象
|
|
787
|
+
* @param params 请求参数 { api_names: string[] }
|
|
788
|
+
* @returns 接口返回结果
|
|
789
|
+
* @example
|
|
790
|
+
* ```typescript
|
|
791
|
+
* // 删除单个对象
|
|
792
|
+
* await client.schema.delete({ api_names: ['object_abc'] });
|
|
793
|
+
*
|
|
794
|
+
* // 删除多个对象
|
|
795
|
+
* await client.schema.delete({ api_names: ['object_abc', 'object_def'] });
|
|
796
|
+
* ```
|
|
797
|
+
*/
|
|
798
|
+
delete: (params: {
|
|
799
|
+
api_names: string[];
|
|
800
|
+
}) => Promise<any>;
|
|
801
|
+
};
|
|
509
802
|
}
|
|
510
803
|
export declare const apaas: {
|
|
511
804
|
Client: typeof Client;
|
|
512
805
|
};
|
|
513
|
-
export {};
|
|
806
|
+
export type { BatchResult, RetryOptions, FieldTypeMetadata, MultilingualText, ObjectSettings, FieldTypeDefinition, EncryptType, FieldOperator, CreateFieldDefinition, UpdateFieldDefinition, CreateObjectDefinition, UpdateObjectDefinition };
|
|
807
|
+
export { FIELD_TYPES, SYSTEM_FIELDS, LANGUAGE_CODES, SCHEMA_GUIDELINES, CREATE_OBJECT_EXAMPLE, UPDATE_OBJECT_ADD_FIELD_EXAMPLE, UPDATE_OBJECT_REPLACE_FIELD_EXAMPLE, UPDATE_OBJECT_REMOVE_FIELD_EXAMPLE, UPDATE_OBJECT_SETTINGS_EXAMPLE, getSystemFields, getCustomFieldTypes, getFieldType, isSystemField, createMultilingualText, extractMultilingualText };
|