apaas-oapi-client 0.1.19 → 0.1.20

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/UserManual.md CHANGED
@@ -191,16 +191,30 @@ const res = await client.object.create.record({
191
191
  console.log(res);
192
192
  ```
193
193
 
194
- ### **批量创建**
194
+ ### **批量创建(最多 100 条)**
195
195
 
196
- > ⚠️ 每次最多创建 100 条,SDK 已自动分组限流
196
+ ```JavaScript
197
+ const res = await client.object.create.records({
198
+ object_name: 'object_event_log',
199
+ records: [
200
+ { name: 'Sample text 1', content: 'Sample text 1' },
201
+ { name: 'Sample text 2', content: 'Sample text 2' }
202
+ ]
203
+ });
204
+ console.log(res);
205
+ ```
206
+
207
+ ### **批量创建(支持超过 100 条,自动拆分)**
208
+
209
+ > ⚠️ 超过 100 条会自动拆分为多次请求,SDK 已自动分组限流
197
210
 
198
211
  ```JavaScript
199
212
  const { total, items } = await client.object.create.recordsWithIterator({
200
213
  object_name: 'object_event_log',
201
214
  records: [
202
215
  { name: 'Sample text 1', content: 'Sample text 1' },
203
- { name: 'Sample text 2', content: 'Sample text 2' }
216
+ { name: 'Sample text 2', content: 'Sample text 2' },
217
+ // ... 可以超过 100 条
204
218
  ]
205
219
  });
206
220
  console.log('Total:', total);
@@ -224,12 +238,10 @@ console.log(res);
224
238
 
225
239
  ***
226
240
 
227
- ### **批量更新**
228
-
229
- > ⚠️ 每次最多更新 100 条,SDK 已自动分组限流
241
+ ### **批量更新(最多 100 条)**
230
242
 
231
243
  ```JavaScript
232
- const res = await client.object.update.recordsBatchUpdate({
244
+ const res = await client.object.update.records({
233
245
  object_name: 'object_store',
234
246
  records: [
235
247
  { _id: 'id1', field1: 'value1' },
@@ -239,6 +251,22 @@ const res = await client.object.update.recordsBatchUpdate({
239
251
  console.log(res);
240
252
  ```
241
253
 
254
+ ### **批量更新(支持超过 100 条,自动拆分)**
255
+
256
+ > ⚠️ 超过 100 条会自动拆分为多次请求,SDK 已自动分组限流
257
+
258
+ ```JavaScript
259
+ const results = await client.object.update.recordsWithIterator({
260
+ object_name: 'object_store',
261
+ records: [
262
+ { _id: 'id1', field1: 'value1' },
263
+ { _id: 'id2', field1: 'value2' },
264
+ // ... 可以超过 100 条
265
+ ]
266
+ });
267
+ console.log(results); // 返回所有子请求的结果数组
268
+ ```
269
+
242
270
  ***
243
271
 
244
272
 
@@ -257,18 +285,28 @@ console.log(res);
257
285
 
258
286
  ***
259
287
 
260
- ### **批量删除**
261
-
262
- > ⚠️ 每次最多删除 100 条,SDK 已自动分组限流
288
+ ### **批量删除(最多 100 条)**
263
289
 
264
290
  ```JavaScript
265
- const res = await client.object.delete.recordsBatchDelete({
291
+ const res = await client.object.delete.records({
266
292
  object_name: 'object_store',
267
293
  ids: ['id1', 'id2', 'id3']
268
294
  });
269
295
  console.log(res);
270
296
  ```
271
297
 
298
+ ### **批量删除(支持超过 100 条,自动拆分)**
299
+
300
+ > ⚠️ 超过 100 条会自动拆分为多次请求,SDK 已自动分组限流
301
+
302
+ ```JavaScript
303
+ const results = await client.object.delete.recordsWithIterator({
304
+ object_name: 'object_store',
305
+ ids: ['id1', 'id2', 'id3', /* ... 可以超过 100 条 */]
306
+ });
307
+ console.log(results); // 返回所有子请求的结果数组
308
+ ```
309
+
272
310
  ***
273
311
 
274
312
 
package/dist/index.js CHANGED
@@ -307,13 +307,17 @@ class Client {
307
307
  */
308
308
  records: async (params) => {
309
309
  const { object_name, records } = params;
310
- const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
310
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
311
311
  this.log(LoggerLevel.info, `[object.update.records] Updating ${records.length} records`);
312
- const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
313
- this.log(LoggerLevel.info, `[object.update.records] Records updated: ${object_name}`);
314
- this.log(LoggerLevel.debug, `[object.update.records] Records updated: ${object_name}, code=${response.data.code}`);
315
- this.log(LoggerLevel.trace, `[object.update.records] Response: ${JSON.stringify(response.data)}`);
316
- return response.data;
312
+ const response = await functionLimiter(async () => {
313
+ await this.ensureTokenValid();
314
+ const res = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
315
+ this.log(LoggerLevel.info, `[object.update.records] Records updated: ${object_name}`);
316
+ this.log(LoggerLevel.debug, `[object.update.records] Records updated: ${object_name}, code=${res.data.code}`);
317
+ this.log(LoggerLevel.trace, `[object.update.records] Response: ${JSON.stringify(res.data)}`);
318
+ return res.data;
319
+ });
320
+ return response;
317
321
  },
318
322
  /**
319
323
  * 批量更新 - 支持超过 100 条数据,自动拆分
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "main": "dist/index.js",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
package/src/index.ts CHANGED
@@ -494,17 +494,23 @@ class Client {
494
494
  */
495
495
  records: async (params: { object_name: string; records: any[] }): Promise<any> => {
496
496
  const { object_name, records } = params;
497
- const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
497
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
498
498
 
499
499
  this.log(LoggerLevel.info, `[object.update.records] Updating ${records.length} records`);
500
500
 
501
- const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
501
+ const response = await functionLimiter(async () => {
502
+ await this.ensureTokenValid();
503
+
504
+ const res = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
502
505
 
503
- this.log(LoggerLevel.info, `[object.update.records] Records updated: ${object_name}`);
504
- this.log(LoggerLevel.debug, `[object.update.records] Records updated: ${object_name}, code=${response.data.code}`);
505
- this.log(LoggerLevel.trace, `[object.update.records] Response: ${JSON.stringify(response.data)}`);
506
+ this.log(LoggerLevel.info, `[object.update.records] Records updated: ${object_name}`);
507
+ this.log(LoggerLevel.debug, `[object.update.records] Records updated: ${object_name}, code=${res.data.code}`);
508
+ this.log(LoggerLevel.trace, `[object.update.records] Response: ${JSON.stringify(res.data)}`);
509
+
510
+ return res.data;
511
+ });
506
512
 
507
- return response.data;
513
+ return response;
508
514
  },
509
515
 
510
516
  /**