apaas-oapi-client 0.1.9 → 0.1.11

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/dist/index.d.ts CHANGED
@@ -3,24 +3,15 @@ import { LoggerLevel } from './logger';
3
3
  * Client 初始化配置
4
4
  */
5
5
  interface ClientOptions {
6
- /** 命名空间,例如 app_xxx */
6
+ /** 命名空间, 例如 app_xxx */
7
7
  namespace: string;
8
8
  /** 应用 clientId */
9
9
  clientId: string;
10
10
  /** 应用 clientSecret */
11
11
  clientSecret: string;
12
- /** 是否禁用 token 缓存,每次调用强制刷新 token,默认 false */
12
+ /** 是否禁用 token 缓存, 每次调用强制刷新 token, 默认 false */
13
13
  disableTokenCache?: boolean;
14
14
  }
15
- /**
16
- * records_query 接口请求参数
17
- */
18
- interface RecordsQueryParams {
19
- /** 对象名称,例如 object_store */
20
- object_name: string;
21
- /** 请求体数据 */
22
- data: any;
23
- }
24
15
  /**
25
16
  * aPaaS OpenAPI 客户端
26
17
  */
@@ -50,7 +41,7 @@ declare class Client {
50
41
  */
51
42
  private log;
52
43
  /**
53
- * 初始化 client,自动获取 token
44
+ * 初始化 client, 自动获取 token
54
45
  */
55
46
  init(): Promise<void>;
56
47
  /**
@@ -58,7 +49,7 @@ declare class Client {
58
49
  */
59
50
  private getAccessToken;
60
51
  /**
61
- * 确保 token 有效,若过期则刷新
52
+ * 确保 token 有效, 若过期则刷新
62
53
  */
63
54
  private ensureTokenValid;
64
55
  /**
@@ -76,6 +67,7 @@ declare class Client {
76
67
  metadata: {
77
68
  /**
78
69
  * 获取指定对象下指定字段的元数据
70
+ * @description 查询指定对象下的单个字段元数据
79
71
  * @param params 请求参数 { object_name, field_name }
80
72
  * @returns 接口返回结果
81
73
  */
@@ -85,6 +77,7 @@ declare class Client {
85
77
  }) => Promise<any>;
86
78
  /**
87
79
  * 获取指定对象的所有字段信息
80
+ * @description 查询指定对象下的所有字段元数据
88
81
  * @param params 请求参数 { object_name }
89
82
  * @returns 接口返回结果
90
83
  */
@@ -95,6 +88,7 @@ declare class Client {
95
88
  search: {
96
89
  /**
97
90
  * 单条记录查询
91
+ * @description 查询指定对象下的单条记录
98
92
  * @param params 请求参数
99
93
  * @returns 接口返回结果
100
94
  */
@@ -104,17 +98,25 @@ declare class Client {
104
98
  select: string[];
105
99
  }) => Promise<any>;
106
100
  /**
107
- * records_query 接口
101
+ * 多条记录查询 - 最多传入 100 条
102
+ * @description 查询指定对象下的多条记录
108
103
  * @param params 请求参数
109
104
  * @returns 接口返回结果
110
105
  */
111
- records: (params: RecordsQueryParams) => Promise<any>;
106
+ records: (params: {
107
+ object_name: string;
108
+ data: any;
109
+ }) => Promise<any>;
112
110
  /**
113
- * 分页查询所有记录
111
+ * 查询所有记录 - 支持超过 100 条数据,自动分页查询
112
+ * @description 该方法会自动处理分页,直到没有更多数据为止
114
113
  * @param params 请求参数
115
114
  * @returns { total, items }
116
115
  */
117
- recordsWithIterator: (params: RecordsQueryParams) => Promise<{
116
+ recordsWithIterator: (params: {
117
+ object_name: string;
118
+ data: any;
119
+ }) => Promise<{
118
120
  total: number;
119
121
  items: any[];
120
122
  }>;
@@ -122,6 +124,7 @@ declare class Client {
122
124
  create: {
123
125
  /**
124
126
  * 单条记录创建
127
+ * @description 创建单条记录到指定对象中
125
128
  * @param params 请求参数 { object_name, record }
126
129
  * @returns 接口返回结果
127
130
  */
@@ -130,7 +133,8 @@ declare class Client {
130
133
  record: any;
131
134
  }) => Promise<any>;
132
135
  /**
133
- * 批量创建记录
136
+ * 批量创建记录 - 最多传入 100 条
137
+ * @description 创建多条记录到指定对象中
134
138
  * @param params 请求参数 { object_name, records }
135
139
  * @returns 接口返回结果
136
140
  */
@@ -139,7 +143,8 @@ declare class Client {
139
143
  records: any[];
140
144
  }) => Promise<any>;
141
145
  /**
142
- * 分批创建所有记录
146
+ * 分批创建所有记录 - 支持超过 100 条数据,自动拆分
147
+ * @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
143
148
  * @param params 请求参数 { object_name, records }
144
149
  * @returns { total, items }
145
150
  */
@@ -154,6 +159,7 @@ declare class Client {
154
159
  update: {
155
160
  /**
156
161
  * 单条更新
162
+ * @description 更新指定对象下的单条记录
157
163
  * @param params 请求参数
158
164
  * @returns 接口返回结果
159
165
  */
@@ -163,11 +169,22 @@ declare class Client {
163
169
  record: any;
164
170
  }) => Promise<any>;
165
171
  /**
166
- * 批量更新
172
+ * 多条更新 - 最多传入 100 条
173
+ * @description 更新指定对象下的多条记录
174
+ * @param params 请求参数
175
+ * @returns 接口返回结果
176
+ */
177
+ records: (params: {
178
+ object_name: string;
179
+ records: any[];
180
+ }) => Promise<any>;
181
+ /**
182
+ * 批量更新 - 支持超过 100 条数据,自动拆分
183
+ * @description 更新指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
167
184
  * @param params 请求参数
168
185
  * @returns 所有子请求的返回结果数组
169
186
  */
170
- recordsBatchUpdate: (params: {
187
+ recordsWithIterator: (params: {
171
188
  object_name: string;
172
189
  records: any[];
173
190
  }) => Promise<any[]>;
@@ -175,6 +192,7 @@ declare class Client {
175
192
  delete: {
176
193
  /**
177
194
  * 单条删除
195
+ * @description 删除指定对象下的单条记录
178
196
  * @param params 请求参数
179
197
  * @returns 接口返回结果
180
198
  */
@@ -182,12 +200,23 @@ declare class Client {
182
200
  object_name: string;
183
201
  record_id: string;
184
202
  }) => Promise<any>;
203
+ /**
204
+ * 多条删除 - 最多传入 100 条
205
+ * @description 删除指定对象下的多条记录
206
+ * @param params 请求参数
207
+ * @returns 接口返回结果
208
+ */
209
+ records: (params: {
210
+ object_name: string;
211
+ ids: string[];
212
+ }) => Promise<any>;
185
213
  /**
186
214
  * 批量删除
215
+ * @description 删除指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
187
216
  * @param params 请求参数
188
217
  * @returns 所有子请求的返回结果数组
189
218
  */
190
- recordsBatchDelete: (params: {
219
+ recordsWithIterator: (params: {
191
220
  object_name: string;
192
221
  ids: string[];
193
222
  }) => Promise<any[]>;
package/dist/index.js CHANGED
@@ -62,6 +62,7 @@ class Client {
62
62
  metadata: {
63
63
  /**
64
64
  * 获取指定对象下指定字段的元数据
65
+ * @description 查询指定对象下的单个字段元数据
65
66
  * @param params 请求参数 { object_name, field_name }
66
67
  * @returns 接口返回结果
67
68
  */
@@ -69,16 +70,17 @@ class Client {
69
70
  const { object_name, field_name } = params;
70
71
  await this.ensureTokenValid();
71
72
  const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/${object_name}/fields/${field_name}`;
72
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据 object_name=${object_name}, field_name=${field_name}`);
73
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据, object_name=${object_name}, field_name=${field_name}`);
73
74
  const res = await this.axiosInstance.get(url, {
74
75
  headers: { Authorization: `${this.accessToken}` }
75
76
  });
76
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 调用完成,返回状态=${res.data.code}`);
77
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 调用完成,返回信息=${JSON.stringify(res.data)}`);
77
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 调用完成, 返回状态=${res.data.code}`);
78
+ this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 返回信息=${JSON.stringify(res.data)}`);
78
79
  return res.data;
79
80
  },
80
81
  /**
81
82
  * 获取指定对象的所有字段信息
83
+ * @description 查询指定对象下的所有字段元数据
82
84
  * @param params 请求参数 { object_name }
83
85
  * @returns 接口返回结果
84
86
  */
@@ -90,14 +92,15 @@ class Client {
90
92
  const res = await this.axiosInstance.get(url, {
91
93
  headers: { Authorization: `${this.accessToken}` }
92
94
  });
93
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 调用完成,返回状态=${res.data.code}`);
94
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 调用完成,返回信息=${JSON.stringify(res.data)}`);
95
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回状态=${res.data.code}`);
96
+ this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回信息=${JSON.stringify(res.data)}`);
95
97
  return res.data;
96
98
  }
97
99
  },
98
100
  search: {
99
101
  /**
100
102
  * 单条记录查询
103
+ * @description 查询指定对象下的单条记录
101
104
  * @param params 请求参数
102
105
  * @returns 接口返回结果
103
106
  */
@@ -108,14 +111,15 @@ class Client {
108
111
  const res = await functionLimiter(async () => {
109
112
  await this.ensureTokenValid();
110
113
  const response = await this.axiosInstance.post(url, { select }, { headers: { Authorization: `${this.accessToken}` } });
111
- this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 record_id: ${record_id} 调用完成,返回状态: ${response.data.code}`);
112
- this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
114
+ this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
115
+ this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
113
116
  return response.data;
114
117
  });
115
118
  return res;
116
119
  },
117
120
  /**
118
- * records_query 接口
121
+ * 多条记录查询 - 最多传入 100 条
122
+ * @description 查询指定对象下的多条记录
119
123
  * @param params 请求参数
120
124
  * @returns 接口返回结果
121
125
  */
@@ -128,12 +132,13 @@ class Client {
128
132
  headers: { Authorization: `${this.accessToken}` }
129
133
  });
130
134
  this.log(LoggerLevel.info, `[批量查询记录] 🔍 接口调用完成`);
131
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 调用完成,返回状态: ${res.data.code},返回数据总数${((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.total) || 'unknown'}`);
132
- this.log(LoggerLevel.trace, `[批量查询记录] 🔍 调用完成,返回信息: ${JSON.stringify(res.data)}`);
135
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回状态: ${res.data.code}, 返回数据总数${((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.total) || 'unknown'}`);
136
+ this.log(LoggerLevel.trace, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
133
137
  return res.data;
134
138
  },
135
139
  /**
136
- * 分页查询所有记录
140
+ * 查询所有记录 - 支持超过 100 条数据,自动分页查询
141
+ * @description 该方法会自动处理分页,直到没有更多数据为止
137
142
  * @param params 请求参数
138
143
  * @returns { total, items }
139
144
  */
@@ -156,11 +161,11 @@ class Client {
156
161
  }
157
162
  if (page === 1) {
158
163
  total = res.data.total || 0;
159
- this.log(LoggerLevel.info, '[批量查询记录] 🔍 接口返回 total:', total);
164
+ this.log(LoggerLevel.info, '[批量查询记录] 🔍 查询object_name=${object_name}, 接口返回 total:', total);
160
165
  }
161
166
  nextPageToken = res.data.next_page_token;
162
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询,nextPageToken: ${nextPageToken || ''}`);
163
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成,items.length: ${res.data.items.length}`);
167
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${nextPageToken || ''}`);
168
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成, items.length: ${res.data.items.length}`);
164
169
  this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify(res.data.items)}`);
165
170
  return res;
166
171
  });
@@ -171,6 +176,7 @@ class Client {
171
176
  create: {
172
177
  /**
173
178
  * 单条记录创建
179
+ * @description 创建单条记录到指定对象中
174
180
  * @param params 请求参数 { object_name, record }
175
181
  * @returns 接口返回结果
176
182
  */
@@ -183,15 +189,16 @@ class Client {
183
189
  const response = await this.axiosInstance.post(url, { record }, {
184
190
  headers: { Authorization: `${this.accessToken}` }
185
191
  });
186
- this.log(LoggerLevel.info, `[单条创建记录] ➕ 向对象 ${object_name} 内创建记录,调用完成`);
187
- this.log(LoggerLevel.debug, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据,调用完成,返回状态: ${response.data.code}`);
188
- this.log(LoggerLevel.trace, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据,调用完成,返回信息: ${JSON.stringify(response.data)}`);
192
+ this.log(LoggerLevel.info, `[单条创建记录] ➕ 向对象 ${object_name} 内创建记录, 调用完成`);
193
+ this.log(LoggerLevel.debug, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据, 调用完成, 返回状态: ${response.data.code}`);
194
+ this.log(LoggerLevel.trace, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
189
195
  return response.data;
190
196
  });
191
197
  return res;
192
198
  },
193
199
  /**
194
- * 批量创建记录
200
+ * 批量创建记录 - 最多传入 100 条
201
+ * @description 创建多条记录到指定对象中
195
202
  * @param params 请求参数 { object_name, records }
196
203
  * @returns 接口返回结果
197
204
  */
@@ -203,12 +210,13 @@ class Client {
203
210
  headers: { Authorization: `${this.accessToken}` }
204
211
  });
205
212
  this.log(LoggerLevel.info, `[批量创建记录] ➕ 开始向对象 ${object_name} 批量创建记录`);
206
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录,调用完成,返回状态: ${res.data.code}`);
207
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录,调用完成,返回信息: ${JSON.stringify(res.data)}`);
213
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录, 调用完成, 返回状态: ${res.data.code}`);
214
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
208
215
  return res.data;
209
216
  },
210
217
  /**
211
- * 分批创建所有记录
218
+ * 分批创建所有记录 - 支持超过 100 条数据,自动拆分
219
+ * @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
212
220
  * @param params 请求参数 { object_name, records }
213
221
  * @returns { total, items }
214
222
  */
@@ -222,12 +230,12 @@ class Client {
222
230
  for (let i = 0; i < records.length; i += chunkSize) {
223
231
  chunks.push(records.slice(i, i + chunkSize));
224
232
  }
225
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
226
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
233
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
234
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
227
235
  for (const [index, chunk] of chunks.entries()) {
228
236
  page += 1;
229
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组,共 ${chunk.length} 条`);
230
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组,共 ${chunk.length} 条`);
237
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, ${chunk.length} 条`);
238
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, ${chunk.length} 条`);
231
239
  await functionLimiter(async () => {
232
240
  const res = await this.object.create.records({
233
241
  object_name,
@@ -236,9 +244,9 @@ class Client {
236
244
  if (res.data && Array.isArray(res.data.items)) {
237
245
  results = results.concat(res.data.items);
238
246
  }
239
- this.log(LoggerLevel.info, `[批量创建记录] ➕ 创建第 ${page} 页数据,调用完成,创建数量: ${res.data.items.length}`);
240
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 创建第 ${page} 页页数据,调用完成,返回状态: ${res.data.code}`);
241
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 创建第 ${page} 页页数据,调用结果: ${JSON.stringify(res.data.items)}`);
247
+ this.log(LoggerLevel.info, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页数据, 调用完成, 创建数量: ${res.data.items.length}`);
248
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用完成, 返回状态: ${res.data.code}`);
249
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用结果: ${JSON.stringify(res.data.items)}`);
242
250
  return res;
243
251
  });
244
252
  }
@@ -248,6 +256,7 @@ class Client {
248
256
  update: {
249
257
  /**
250
258
  * 单条更新
259
+ * @description 更新指定对象下的单条记录
251
260
  * @param params 请求参数
252
261
  * @returns 接口返回结果
253
262
  */
@@ -258,19 +267,36 @@ class Client {
258
267
  const res = await functionLimiter(async () => {
259
268
  await this.ensureTokenValid();
260
269
  const response = await this.axiosInstance.patch(url, { record }, { headers: { Authorization: `${this.accessToken}` } });
261
- this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成`);
262
- this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成,返回状态: ${response.data.code}`);
263
- this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
270
+ this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成`);
271
+ this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
272
+ this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
264
273
  return response.data;
265
274
  });
266
275
  return res;
267
276
  },
268
277
  /**
269
- * 批量更新
278
+ * 多条更新 - 最多传入 100 条
279
+ * @description 更新指定对象下的多条记录
280
+ * @param params 请求参数
281
+ * @returns 接口返回结果
282
+ */
283
+ records: async (params) => {
284
+ const { object_name, records } = params;
285
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
286
+ this.log(LoggerLevel.info, `[多条更新记录] 💾 开始更新 ${records.length} 条数据`);
287
+ const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
288
+ this.log(LoggerLevel.info, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成`);
289
+ this.log(LoggerLevel.debug, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回状态: ${response.data.code}`);
290
+ this.log(LoggerLevel.trace, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
291
+ return response.data;
292
+ },
293
+ /**
294
+ * 批量更新 - 支持超过 100 条数据,自动拆分
295
+ * @description 更新指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
270
296
  * @param params 请求参数
271
297
  * @returns 所有子请求的返回结果数组
272
298
  */
273
- recordsBatchUpdate: async (params) => {
299
+ recordsWithIterator: async (params) => {
274
300
  const { object_name, records } = params;
275
301
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
276
302
  const chunkSize = 100;
@@ -278,17 +304,17 @@ class Client {
278
304
  for (let i = 0; i < records.length; i += chunkSize) {
279
305
  chunks.push(records.slice(i, i + chunkSize));
280
306
  }
281
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
282
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
307
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
308
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
283
309
  const results = [];
284
310
  for (const [index, chunk] of chunks.entries()) {
285
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组,共 ${chunk.length} 条`);
286
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组,共 ${chunk.length} 条`);
311
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, ${chunk.length} 条`);
312
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, ${chunk.length} 条`);
287
313
  const res = await functionLimiter(async () => {
288
314
  await this.ensureTokenValid();
289
315
  const response = await this.axiosInstance.patch(url, { records: chunk }, { headers: { Authorization: `${this.accessToken}` } });
290
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新第 ${index + 1} 组调用完成,返回状态: ${JSON.stringify(response.data)}`);
291
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新第 ${index + 1} 组调用完成,返回信息: ${response.data}`);
316
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回状态: ${JSON.stringify(response.data)}`);
317
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回信息: ${response.data}`);
292
318
  return response.data;
293
319
  });
294
320
  results.push(res);
@@ -299,29 +325,54 @@ class Client {
299
325
  delete: {
300
326
  /**
301
327
  * 单条删除
328
+ * @description 删除指定对象下的单条记录
302
329
  * @param params 请求参数
303
330
  * @returns 接口返回结果
304
331
  */
305
332
  record: async (params) => {
306
333
  const { object_name, record_id } = params;
307
334
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
308
- this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ 开始删除 record_id: ${record_id}`);
335
+ this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ object_name=${object_name}, 开始删除 record_id: ${record_id}`);
309
336
  const res = await functionLimiter(async () => {
310
337
  await this.ensureTokenValid();
311
338
  const response = await this.axiosInstance.delete(url, {
312
339
  headers: { Authorization: `${this.accessToken}` }
313
340
  });
314
- this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
341
+ this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
342
+ return response.data;
343
+ });
344
+ return res;
345
+ },
346
+ /**
347
+ * 多条删除 - 最多传入 100 条
348
+ * @description 删除指定对象下的多条记录
349
+ * @param params 请求参数
350
+ * @returns 接口返回结果
351
+ */
352
+ records: async (params) => {
353
+ const { object_name, ids } = params;
354
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
355
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除对象 ${object_name} 的 ${ids.length} 条记录`);
356
+ const res = await functionLimiter(async () => {
357
+ await this.ensureTokenValid();
358
+ const response = await this.axiosInstance.delete(url, {
359
+ data: { ids },
360
+ headers: { Authorization: `${this.accessToken}`, 'Content-Type': 'application/json' }
361
+ });
362
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成`);
363
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回状态: ${response.data.code}`);
364
+ this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回信息: ${JSON.stringify(response.data)}`);
315
365
  return response.data;
316
366
  });
317
367
  return res;
318
368
  },
319
369
  /**
320
370
  * 批量删除
371
+ * @description 删除指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
321
372
  * @param params 请求参数
322
373
  * @returns 所有子请求的返回结果数组
323
374
  */
324
- recordsBatchDelete: async (params) => {
375
+ recordsWithIterator: async (params) => {
325
376
  const { object_name, ids } = params;
326
377
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
327
378
  const chunkSize = 100;
@@ -329,18 +380,18 @@ class Client {
329
380
  for (let i = 0; i < ids.length; i += chunkSize) {
330
381
  chunks.push(ids.slice(i, i + chunkSize));
331
382
  }
332
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
383
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
333
384
  const results = [];
334
385
  for (const [index, chunk] of chunks.entries()) {
335
- this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组,共 ${chunk.length} 条`);
386
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组, ${chunk.length} 条`);
336
387
  const res = await functionLimiter(async () => {
337
388
  await this.ensureTokenValid();
338
389
  const response = await this.axiosInstance.delete(url, {
339
390
  headers: { Authorization: `${this.accessToken}` },
340
391
  data: { ids: chunk }
341
392
  });
342
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成,返回状态: ${response.data.code}`);
343
- this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成,返回信息: ${JSON.stringify(response.data)}`);
393
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成, 返回状态: ${response.data.code}`);
394
+ this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成, 返回信息: ${JSON.stringify(response.data)}`);
344
395
  return response.data;
345
396
  });
346
397
  results.push(res);
@@ -362,7 +413,7 @@ class Client {
362
413
  const { department_id_type, department_id } = params;
363
414
  // department_id_type 可选值:
364
415
  // - 'department_id' (如 "1758534140403815")
365
- // - 'external_department_id' (外部平台 department_id,无固定格式)
416
+ // - 'external_department_id' (外部平台 department_id, 无固定格式)
366
417
  // - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
367
418
  const url = '/api/integration/v2/feishu/getDepartments';
368
419
  this.log(LoggerLevel.info, `[部门ID交换] 🔄 开始交换单个部门 ID: ${department_id}`);
@@ -374,8 +425,8 @@ class Client {
374
425
  }, {
375
426
  headers: { Authorization: `${this.accessToken}` }
376
427
  });
377
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成,返回状态: ${response.data.code}`);
378
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
428
+ this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回状态: ${response.data.code}`);
429
+ this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
379
430
  return response.data.data[0]; // 返回第一个元素
380
431
  });
381
432
  return res;
@@ -389,7 +440,7 @@ class Client {
389
440
  const { department_id_type, department_ids } = params;
390
441
  // department_id_type 可选值:
391
442
  // - 'department_id' (如 "1758534140403815")
392
- // - 'external_department_id' (外部平台 department_id,无固定格式)
443
+ // - 'external_department_id' (外部平台 department_id, 无固定格式)
393
444
  // - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
394
445
  const url = '/api/integration/v2/feishu/getDepartments';
395
446
  const chunkSize = 100;
@@ -397,10 +448,10 @@ class Client {
397
448
  for (let i = 0; i < department_ids.length; i += chunkSize) {
398
449
  chunks.push(department_ids.slice(i, i + chunkSize));
399
450
  }
400
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 个`);
451
+ this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 个`);
401
452
  const results = [];
402
453
  for (const [index, chunk] of chunks.entries()) {
403
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组,共 ${chunk.length} 个`);
454
+ this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组, ${chunk.length} 个`);
404
455
  const res = await functionLimiter(async () => {
405
456
  await this.ensureTokenValid();
406
457
  const response = await this.axiosInstance.post(url, {
@@ -409,8 +460,8 @@ class Client {
409
460
  }, {
410
461
  headers: { Authorization: `${this.accessToken}` }
411
462
  });
412
- this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成,返回状态: ${response.data.code}`);
413
- this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成,返回信息: ${JSON.stringify(response.data)}`);
463
+ this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回状态: ${response.data.code}`);
464
+ this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回信息: ${JSON.stringify(response.data)}`);
414
465
  return response.data.data;
415
466
  });
416
467
  results.push(...res);
@@ -438,8 +489,8 @@ class Client {
438
489
  'Content-Type': 'application/json'
439
490
  }
440
491
  });
441
- this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成,返回状态: code=${res.data.code}`);
442
- this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成,返回信息: code=${JSON.stringify(res.data)}`);
492
+ this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回状态: code=${res.data.code}`);
493
+ this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回信息: code=${JSON.stringify(res.data)}`);
443
494
  return res.data;
444
495
  }
445
496
  };
@@ -474,7 +525,7 @@ class Client {
474
525
  }
475
526
  }
476
527
  /**
477
- * 初始化 client,自动获取 token
528
+ * 初始化 client, 自动获取 token
478
529
  */
479
530
  async init() {
480
531
  await this.ensureTokenValid();
@@ -498,7 +549,7 @@ class Client {
498
549
  this.log(LoggerLevel.info, '[client] token refreshed');
499
550
  }
500
551
  /**
501
- * 确保 token 有效,若过期则刷新
552
+ * 确保 token 有效, 若过期则刷新
502
553
  */
503
554
  async ensureTokenValid() {
504
555
  if (this.disableTokenCache) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "main": "dist/index.js",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
package/src/index.ts CHANGED
@@ -7,13 +7,13 @@ import { functionLimiter } from './limiter';
7
7
  * Client 初始化配置
8
8
  */
9
9
  interface ClientOptions {
10
- /** 命名空间,例如 app_xxx */
10
+ /** 命名空间, 例如 app_xxx */
11
11
  namespace: string;
12
12
  /** 应用 clientId */
13
13
  clientId: string;
14
14
  /** 应用 clientSecret */
15
15
  clientSecret: string;
16
- /** 是否禁用 token 缓存,每次调用强制刷新 token,默认 false */
16
+ /** 是否禁用 token 缓存, 每次调用强制刷新 token, 默认 false */
17
17
  disableTokenCache?: boolean;
18
18
  }
19
19
 
@@ -29,16 +29,6 @@ interface TokenResponse {
29
29
  msg: string;
30
30
  }
31
31
 
32
- /**
33
- * records_query 接口请求参数
34
- */
35
- interface RecordsQueryParams {
36
- /** 对象名称,例如 object_store */
37
- object_name: string;
38
- /** 请求体数据 */
39
- data: any;
40
- }
41
-
42
32
  /**
43
33
  * aPaaS OpenAPI 客户端
44
34
  */
@@ -92,7 +82,7 @@ class Client {
92
82
  }
93
83
  }
94
84
  /**
95
- * 初始化 client,自动获取 token
85
+ * 初始化 client, 自动获取 token
96
86
  */
97
87
  async init() {
98
88
  await this.ensureTokenValid();
@@ -120,7 +110,7 @@ class Client {
120
110
  }
121
111
 
122
112
  /**
123
- * 确保 token 有效,若过期则刷新
113
+ * 确保 token 有效, 若过期则刷新
124
114
  */
125
115
  private async ensureTokenValid() {
126
116
  if (this.disableTokenCache) {
@@ -164,6 +154,7 @@ class Client {
164
154
  metadata: {
165
155
  /**
166
156
  * 获取指定对象下指定字段的元数据
157
+ * @description 查询指定对象下的单个字段元数据
167
158
  * @param params 请求参数 { object_name, field_name }
168
159
  * @returns 接口返回结果
169
160
  */
@@ -172,19 +163,20 @@ class Client {
172
163
  await this.ensureTokenValid();
173
164
  const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/${object_name}/fields/${field_name}`;
174
165
 
175
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据 object_name=${object_name}, field_name=${field_name}`);
166
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据, object_name=${object_name}, field_name=${field_name}`);
176
167
 
177
168
  const res = await this.axiosInstance.get(url, {
178
169
  headers: { Authorization: `${this.accessToken}` }
179
170
  });
180
171
 
181
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 调用完成,返回状态=${res.data.code}`);
182
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 调用完成,返回信息=${JSON.stringify(res.data)}`);
172
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 调用完成, 返回状态=${res.data.code}`);
173
+ this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 返回信息=${JSON.stringify(res.data)}`);
183
174
  return res.data;
184
175
  },
185
176
 
186
177
  /**
187
178
  * 获取指定对象的所有字段信息
179
+ * @description 查询指定对象下的所有字段元数据
188
180
  * @param params 请求参数 { object_name }
189
181
  * @returns 接口返回结果
190
182
  */
@@ -199,8 +191,8 @@ class Client {
199
191
  headers: { Authorization: `${this.accessToken}` }
200
192
  });
201
193
 
202
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 调用完成,返回状态=${res.data.code}`);
203
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 调用完成,返回信息=${JSON.stringify(res.data)}`);
194
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回状态=${res.data.code}`);
195
+ this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回信息=${JSON.stringify(res.data)}`);
204
196
  return res.data;
205
197
  }
206
198
  },
@@ -208,6 +200,7 @@ class Client {
208
200
  search: {
209
201
  /**
210
202
  * 单条记录查询
203
+ * @description 查询指定对象下的单条记录
211
204
  * @param params 请求参数
212
205
  * @returns 接口返回结果
213
206
  */
@@ -222,8 +215,8 @@ class Client {
222
215
 
223
216
  const response = await this.axiosInstance.post(url, { select }, { headers: { Authorization: `${this.accessToken}` } });
224
217
 
225
- this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 record_id: ${record_id} 调用完成,返回状态: ${response.data.code}`);
226
- this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
218
+ this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
219
+ this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
227
220
 
228
221
  return response.data;
229
222
  });
@@ -232,11 +225,12 @@ class Client {
232
225
  },
233
226
 
234
227
  /**
235
- * records_query 接口
228
+ * 多条记录查询 - 最多传入 100 条
229
+ * @description 查询指定对象下的多条记录
236
230
  * @param params 请求参数
237
231
  * @returns 接口返回结果
238
232
  */
239
- records: async (params: RecordsQueryParams): Promise<any> => {
233
+ records: async (params: { object_name: string; data: any }): Promise<any> => {
240
234
  const { object_name, data } = params;
241
235
  await this.ensureTokenValid();
242
236
 
@@ -247,17 +241,18 @@ class Client {
247
241
  });
248
242
 
249
243
  this.log(LoggerLevel.info, `[批量查询记录] 🔍 接口调用完成`);
250
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 调用完成,返回状态: ${res.data.code},返回数据总数${res.data?.data?.total || 'unknown'}`);
251
- this.log(LoggerLevel.trace, `[批量查询记录] 🔍 调用完成,返回信息: ${JSON.stringify(res.data)}`);
244
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回状态: ${res.data.code}, 返回数据总数${res.data?.data?.total || 'unknown'}`);
245
+ this.log(LoggerLevel.trace, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
252
246
  return res.data;
253
247
  },
254
248
 
255
249
  /**
256
- * 分页查询所有记录
250
+ * 查询所有记录 - 支持超过 100 条数据,自动分页查询
251
+ * @description 该方法会自动处理分页,直到没有更多数据为止
257
252
  * @param params 请求参数
258
253
  * @returns { total, items }
259
254
  */
260
- recordsWithIterator: async (params: RecordsQueryParams): Promise<{ total: number; items: any[] }> => {
255
+ recordsWithIterator: async (params: { object_name: string; data: any }): Promise<{ total: number; items: any[] }> => {
261
256
  const { object_name, data } = params;
262
257
 
263
258
  let results: any[] = [];
@@ -282,13 +277,13 @@ class Client {
282
277
 
283
278
  if (page === 1) {
284
279
  total = res.data.total || 0;
285
- this.log(LoggerLevel.info, '[批量查询记录] 🔍 接口返回 total:', total);
280
+ this.log(LoggerLevel.info, '[批量查询记录] 🔍 查询object_name=${object_name}, 接口返回 total:', total);
286
281
  }
287
282
 
288
283
  nextPageToken = res.data.next_page_token;
289
284
 
290
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询,nextPageToken: ${nextPageToken || ''}`);
291
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成,items.length: ${res.data.items.length}`);
285
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${nextPageToken || ''}`);
286
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成, items.length: ${res.data.items.length}`);
292
287
  this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify(res.data.items)}`);
293
288
  return res;
294
289
  });
@@ -301,6 +296,7 @@ class Client {
301
296
  create: {
302
297
  /**
303
298
  * 单条记录创建
299
+ * @description 创建单条记录到指定对象中
304
300
  * @param params 请求参数 { object_name, record }
305
301
  * @returns 接口返回结果
306
302
  */
@@ -321,9 +317,9 @@ class Client {
321
317
  }
322
318
  );
323
319
 
324
- this.log(LoggerLevel.info, `[单条创建记录] ➕ 向对象 ${object_name} 内创建记录,调用完成`);
325
- this.log(LoggerLevel.debug, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据,调用完成,返回状态: ${response.data.code}`);
326
- this.log(LoggerLevel.trace, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据,调用完成,返回信息: ${JSON.stringify(response.data)}`);
320
+ this.log(LoggerLevel.info, `[单条创建记录] ➕ 向对象 ${object_name} 内创建记录, 调用完成`);
321
+ this.log(LoggerLevel.debug, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据, 调用完成, 返回状态: ${response.data.code}`);
322
+ this.log(LoggerLevel.trace, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
327
323
 
328
324
  return response.data;
329
325
  });
@@ -332,7 +328,8 @@ class Client {
332
328
  },
333
329
 
334
330
  /**
335
- * 批量创建记录
331
+ * 批量创建记录 - 最多传入 100 条
332
+ * @description 创建多条记录到指定对象中
336
333
  * @param params 请求参数 { object_name, records }
337
334
  * @returns 接口返回结果
338
335
  */
@@ -351,13 +348,14 @@ class Client {
351
348
  );
352
349
 
353
350
  this.log(LoggerLevel.info, `[批量创建记录] ➕ 开始向对象 ${object_name} 批量创建记录`);
354
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录,调用完成,返回状态: ${res.data.code}`);
355
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录,调用完成,返回信息: ${JSON.stringify(res.data)}`);
351
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录, 调用完成, 返回状态: ${res.data.code}`);
352
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
356
353
  return res.data;
357
354
  },
358
355
 
359
356
  /**
360
- * 分批创建所有记录
357
+ * 分批创建所有记录 - 支持超过 100 条数据,自动拆分
358
+ * @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
361
359
  * @param params 请求参数 { object_name, records }
362
360
  * @returns { total, items }
363
361
  */
@@ -374,14 +372,14 @@ class Client {
374
372
  chunks.push(records.slice(i, i + chunkSize));
375
373
  }
376
374
 
377
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
378
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
375
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
376
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
379
377
 
380
378
  for (const [index, chunk] of chunks.entries()) {
381
379
  page += 1;
382
380
 
383
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组,共 ${chunk.length} 条`);
384
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组,共 ${chunk.length} 条`);
381
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, ${chunk.length} 条`);
382
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, ${chunk.length} 条`);
385
383
 
386
384
  const pageRes = await functionLimiter(async () => {
387
385
  const res = await this.object.create.records({
@@ -393,9 +391,9 @@ class Client {
393
391
  results = results.concat(res.data.items);
394
392
  }
395
393
 
396
- this.log(LoggerLevel.info, `[批量创建记录] ➕ 创建第 ${page} 页数据,调用完成,创建数量: ${res.data.items.length}`);
397
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 创建第 ${page} 页页数据,调用完成,返回状态: ${res.data.code}`);
398
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 创建第 ${page} 页页数据,调用结果: ${JSON.stringify(res.data.items)}`);
394
+ this.log(LoggerLevel.info, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页数据, 调用完成, 创建数量: ${res.data.items.length}`);
395
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用完成, 返回状态: ${res.data.code}`);
396
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用结果: ${JSON.stringify(res.data.items)}`);
399
397
 
400
398
  return res;
401
399
  });
@@ -408,6 +406,7 @@ class Client {
408
406
  update: {
409
407
  /**
410
408
  * 单条更新
409
+ * @description 更新指定对象下的单条记录
411
410
  * @param params 请求参数
412
411
  * @returns 接口返回结果
413
412
  */
@@ -422,9 +421,9 @@ class Client {
422
421
 
423
422
  const response = await this.axiosInstance.patch(url, { record }, { headers: { Authorization: `${this.accessToken}` } });
424
423
 
425
- this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成`);
426
- this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成,返回状态: ${response.data.code}`);
427
- this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
424
+ this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成`);
425
+ this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
426
+ this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
428
427
  return response.data;
429
428
  });
430
429
 
@@ -432,11 +431,33 @@ class Client {
432
431
  },
433
432
 
434
433
  /**
435
- * 批量更新
434
+ * 多条更新 - 最多传入 100 条
435
+ * @description 更新指定对象下的多条记录
436
+ * @param params 请求参数
437
+ * @returns 接口返回结果
438
+ */
439
+ records: async (params: { object_name: string; records: any[] }): Promise<any> => {
440
+ const { object_name, records } = params;
441
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
442
+
443
+ this.log(LoggerLevel.info, `[多条更新记录] 💾 开始更新 ${records.length} 条数据`);
444
+
445
+ const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
446
+
447
+ this.log(LoggerLevel.info, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成`);
448
+ this.log(LoggerLevel.debug, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回状态: ${response.data.code}`);
449
+ this.log(LoggerLevel.trace, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
450
+
451
+ return response.data;
452
+ },
453
+
454
+ /**
455
+ * 批量更新 - 支持超过 100 条数据,自动拆分
456
+ * @description 更新指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
436
457
  * @param params 请求参数
437
458
  * @returns 所有子请求的返回结果数组
438
459
  */
439
- recordsBatchUpdate: async (params: { object_name: string; records: any[] }): Promise<any[]> => {
460
+ recordsWithIterator: async (params: { object_name: string; records: any[] }): Promise<any[]> => {
440
461
  const { object_name, records } = params;
441
462
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
442
463
 
@@ -446,21 +467,21 @@ class Client {
446
467
  chunks.push(records.slice(i, i + chunkSize));
447
468
  }
448
469
 
449
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
450
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
470
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
471
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
451
472
 
452
473
  const results: any[] = [];
453
474
  for (const [index, chunk] of chunks.entries()) {
454
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组,共 ${chunk.length} 条`);
455
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组,共 ${chunk.length} 条`);
475
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, ${chunk.length} 条`);
476
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, ${chunk.length} 条`);
456
477
 
457
478
  const res = await functionLimiter(async () => {
458
479
  await this.ensureTokenValid();
459
480
 
460
481
  const response = await this.axiosInstance.patch(url, { records: chunk }, { headers: { Authorization: `${this.accessToken}` } });
461
482
 
462
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新第 ${index + 1} 组调用完成,返回状态: ${JSON.stringify(response.data)}`);
463
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新第 ${index + 1} 组调用完成,返回信息: ${response.data}`);
483
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回状态: ${JSON.stringify(response.data)}`);
484
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回信息: ${response.data}`);
464
485
  return response.data;
465
486
  });
466
487
 
@@ -474,6 +495,7 @@ class Client {
474
495
  delete: {
475
496
  /**
476
497
  * 单条删除
498
+ * @description 删除指定对象下的单条记录
477
499
  * @param params 请求参数
478
500
  * @returns 接口返回结果
479
501
  */
@@ -481,7 +503,7 @@ class Client {
481
503
  const { object_name, record_id } = params;
482
504
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
483
505
 
484
- this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ 开始删除 record_id: ${record_id}`);
506
+ this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ object_name=${object_name}, 开始删除 record_id: ${record_id}`);
485
507
 
486
508
  const res = await functionLimiter(async () => {
487
509
  await this.ensureTokenValid();
@@ -490,7 +512,37 @@ class Client {
490
512
  headers: { Authorization: `${this.accessToken}` }
491
513
  });
492
514
 
493
- this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
515
+ this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
516
+ return response.data;
517
+ });
518
+
519
+ return res;
520
+ },
521
+
522
+ /**
523
+ * 多条删除 - 最多传入 100 条
524
+ * @description 删除指定对象下的多条记录
525
+ * @param params 请求参数
526
+ * @returns 接口返回结果
527
+ */
528
+ records: async (params: { object_name: string; ids: string[] }): Promise<any> => {
529
+ const { object_name, ids } = params;
530
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
531
+
532
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除对象 ${object_name} 的 ${ids.length} 条记录`);
533
+
534
+ const res = await functionLimiter(async () => {
535
+ await this.ensureTokenValid();
536
+
537
+ const response = await this.axiosInstance.delete(url, {
538
+ data: { ids },
539
+ headers: { Authorization: `${this.accessToken}`, 'Content-Type': 'application/json' }
540
+ });
541
+
542
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成`);
543
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回状态: ${response.data.code}`);
544
+ this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回信息: ${JSON.stringify(response.data)}`);
545
+
494
546
  return response.data;
495
547
  });
496
548
 
@@ -499,10 +551,11 @@ class Client {
499
551
 
500
552
  /**
501
553
  * 批量删除
554
+ * @description 删除指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
502
555
  * @param params 请求参数
503
556
  * @returns 所有子请求的返回结果数组
504
557
  */
505
- recordsBatchDelete: async (params: { object_name: string; ids: string[] }): Promise<any[]> => {
558
+ recordsWithIterator: async (params: { object_name: string; ids: string[] }): Promise<any[]> => {
506
559
  const { object_name, ids } = params;
507
560
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
508
561
 
@@ -512,11 +565,11 @@ class Client {
512
565
  chunks.push(ids.slice(i, i + chunkSize));
513
566
  }
514
567
 
515
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
568
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
516
569
 
517
570
  const results: any[] = [];
518
571
  for (const [index, chunk] of chunks.entries()) {
519
- this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组,共 ${chunk.length} 条`);
572
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组, ${chunk.length} 条`);
520
573
 
521
574
  const res = await functionLimiter(async () => {
522
575
  await this.ensureTokenValid();
@@ -526,8 +579,8 @@ class Client {
526
579
  data: { ids: chunk }
527
580
  });
528
581
 
529
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成,返回状态: ${response.data.code}`);
530
- this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成,返回信息: ${JSON.stringify(response.data)}`);
582
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成, 返回状态: ${response.data.code}`);
583
+ this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成, 返回信息: ${JSON.stringify(response.data)}`);
531
584
  return response.data;
532
585
  });
533
586
 
@@ -552,7 +605,7 @@ class Client {
552
605
  const { department_id_type, department_id } = params;
553
606
  // department_id_type 可选值:
554
607
  // - 'department_id' (如 "1758534140403815")
555
- // - 'external_department_id' (外部平台 department_id,无固定格式)
608
+ // - 'external_department_id' (外部平台 department_id, 无固定格式)
556
609
  // - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
557
610
 
558
611
  const url = '/api/integration/v2/feishu/getDepartments';
@@ -573,8 +626,8 @@ class Client {
573
626
  }
574
627
  );
575
628
 
576
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成,返回状态: ${response.data.code}`);
577
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
629
+ this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回状态: ${response.data.code}`);
630
+ this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
578
631
  return response.data.data[0]; // 返回第一个元素
579
632
  });
580
633
 
@@ -590,7 +643,7 @@ class Client {
590
643
  const { department_id_type, department_ids } = params;
591
644
  // department_id_type 可选值:
592
645
  // - 'department_id' (如 "1758534140403815")
593
- // - 'external_department_id' (外部平台 department_id,无固定格式)
646
+ // - 'external_department_id' (外部平台 department_id, 无固定格式)
594
647
  // - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
595
648
 
596
649
  const url = '/api/integration/v2/feishu/getDepartments';
@@ -601,11 +654,11 @@ class Client {
601
654
  chunks.push(department_ids.slice(i, i + chunkSize));
602
655
  }
603
656
 
604
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 个`);
657
+ this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 个`);
605
658
 
606
659
  const results: any[] = [];
607
660
  for (const [index, chunk] of chunks.entries()) {
608
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组,共 ${chunk.length} 个`);
661
+ this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组, ${chunk.length} 个`);
609
662
 
610
663
  const res = await functionLimiter(async () => {
611
664
  await this.ensureTokenValid();
@@ -621,8 +674,8 @@ class Client {
621
674
  }
622
675
  );
623
676
 
624
- this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成,返回状态: ${response.data.code}`);
625
- this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成,返回信息: ${JSON.stringify(response.data)}`);
677
+ this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回状态: ${response.data.code}`);
678
+ this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回信息: ${JSON.stringify(response.data)}`);
626
679
  return response.data.data;
627
680
  });
628
681
 
@@ -661,8 +714,8 @@ class Client {
661
714
  }
662
715
  );
663
716
 
664
- this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成,返回状态: code=${res.data.code}`);
665
- this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成,返回信息: code=${JSON.stringify(res.data)}`);
717
+ this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回状态: code=${res.data.code}`);
718
+ this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回信息: code=${JSON.stringify(res.data)}`);
666
719
 
667
720
  return res.data;
668
721
  }