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 +49 -11
- package/dist/index.js +10 -6
- package/package.json +1 -1
- package/src/index.ts +12 -6
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
|
-
|
|
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.
|
|
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.
|
|
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}/
|
|
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
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
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}/
|
|
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
|
|
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
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
|
513
|
+
return response;
|
|
508
514
|
},
|
|
509
515
|
|
|
510
516
|
/**
|