apaas-oapi-client 0.1.24 → 0.1.26
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.js +16 -14
- package/dist/src/index.d.ts +4 -1
- package/package.json +1 -1
- package/src/index.ts +20 -19
package/dist/index.js
CHANGED
|
@@ -260,11 +260,11 @@ class Client {
|
|
|
260
260
|
/**
|
|
261
261
|
* 分批创建所有记录 - 支持超过 100 条数据,自动拆分
|
|
262
262
|
* @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
|
|
263
|
-
* @param params 请求参数 { object_name, records }
|
|
263
|
+
* @param params 请求参数 { object_name, records, limit }
|
|
264
264
|
* @returns { total, items }
|
|
265
265
|
*/
|
|
266
266
|
recordsWithIterator: async (params) => {
|
|
267
|
-
const { object_name, records } = params;
|
|
267
|
+
const { object_name, records, limit = 100 } = params;
|
|
268
268
|
// 参数校验
|
|
269
269
|
if (!records || !Array.isArray(records)) {
|
|
270
270
|
this.log(LoggerLevel.error, '[object.create.recordsWithIterator] Invalid records parameter: must be a non-empty array');
|
|
@@ -276,7 +276,7 @@ class Client {
|
|
|
276
276
|
}
|
|
277
277
|
let results = [];
|
|
278
278
|
let total = records.length;
|
|
279
|
-
const chunkSize =
|
|
279
|
+
const chunkSize = limit;
|
|
280
280
|
let page = 0;
|
|
281
281
|
const chunks = [];
|
|
282
282
|
for (let i = 0; i < records.length; i += chunkSize) {
|
|
@@ -359,7 +359,7 @@ class Client {
|
|
|
359
359
|
* @returns 所有子请求的返回结果数组
|
|
360
360
|
*/
|
|
361
361
|
recordsWithIterator: async (params) => {
|
|
362
|
-
const { object_name, records } = params;
|
|
362
|
+
const { object_name, records, limit = 100 } = params;
|
|
363
363
|
// 参数校验
|
|
364
364
|
if (!records || !Array.isArray(records)) {
|
|
365
365
|
this.log(LoggerLevel.error, '[object.update.recordsWithIterator] Invalid records parameter: must be a non-empty array');
|
|
@@ -369,8 +369,7 @@ class Client {
|
|
|
369
369
|
this.log(LoggerLevel.warn, '[object.update.recordsWithIterator] Empty records array provided, returning empty result');
|
|
370
370
|
return [];
|
|
371
371
|
}
|
|
372
|
-
const
|
|
373
|
-
const chunkSize = 100;
|
|
372
|
+
const chunkSize = limit;
|
|
374
373
|
const chunks = [];
|
|
375
374
|
for (let i = 0; i < records.length; i += chunkSize) {
|
|
376
375
|
chunks.push(records.slice(i, i + chunkSize));
|
|
@@ -379,13 +378,16 @@ class Client {
|
|
|
379
378
|
const results = [];
|
|
380
379
|
for (const [index, chunk] of chunks.entries()) {
|
|
381
380
|
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
382
|
-
const res = await
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Chunk ${index + 1} completed: ${object_name}, code=${response.data.code}`);
|
|
386
|
-
this.log(LoggerLevel.trace, `[object.update.recordsWithIterator] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
|
|
387
|
-
return response.data;
|
|
381
|
+
const res = await this.object.update.records({
|
|
382
|
+
object_name,
|
|
383
|
+
records: chunk
|
|
388
384
|
});
|
|
385
|
+
if (res.code !== '0') {
|
|
386
|
+
this.log(LoggerLevel.error, `[object.update.recordsWithIterator] Error updating records: code=${res.code}, msg=${res.msg}`);
|
|
387
|
+
throw new Error(res.msg || `Update failed with code ${res.code}`);
|
|
388
|
+
}
|
|
389
|
+
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Chunk ${index + 1} completed: ${object_name}, code=${res.code}`);
|
|
390
|
+
this.log(LoggerLevel.trace, `[object.update.recordsWithIterator] Chunk ${index + 1} response: ${JSON.stringify(res)}`);
|
|
389
391
|
results.push(res);
|
|
390
392
|
}
|
|
391
393
|
return results;
|
|
@@ -444,7 +446,7 @@ class Client {
|
|
|
444
446
|
* @returns 所有子请求的返回结果数组
|
|
445
447
|
*/
|
|
446
448
|
recordsWithIterator: async (params) => {
|
|
447
|
-
const { object_name, ids } = params;
|
|
449
|
+
const { object_name, ids, limit = 100 } = params;
|
|
448
450
|
// 参数校验
|
|
449
451
|
if (!ids || !Array.isArray(ids)) {
|
|
450
452
|
this.log(LoggerLevel.error, '[object.delete.recordsWithIterator] Invalid ids parameter: must be a non-empty array');
|
|
@@ -455,7 +457,7 @@ class Client {
|
|
|
455
457
|
return [];
|
|
456
458
|
}
|
|
457
459
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
458
|
-
const chunkSize =
|
|
460
|
+
const chunkSize = limit;
|
|
459
461
|
const chunks = [];
|
|
460
462
|
for (let i = 0; i < ids.length; i += chunkSize) {
|
|
461
463
|
chunks.push(ids.slice(i, i + chunkSize));
|
package/dist/src/index.d.ts
CHANGED
|
@@ -163,12 +163,13 @@ declare class Client {
|
|
|
163
163
|
/**
|
|
164
164
|
* 分批创建所有记录 - 支持超过 100 条数据,自动拆分
|
|
165
165
|
* @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
|
|
166
|
-
* @param params 请求参数 { object_name, records }
|
|
166
|
+
* @param params 请求参数 { object_name, records, limit }
|
|
167
167
|
* @returns { total, items }
|
|
168
168
|
*/
|
|
169
169
|
recordsWithIterator: (params: {
|
|
170
170
|
object_name: string;
|
|
171
171
|
records: any[];
|
|
172
|
+
limit?: number;
|
|
172
173
|
}) => Promise<{
|
|
173
174
|
total: number;
|
|
174
175
|
items: any[];
|
|
@@ -205,6 +206,7 @@ declare class Client {
|
|
|
205
206
|
recordsWithIterator: (params: {
|
|
206
207
|
object_name: string;
|
|
207
208
|
records: any[];
|
|
209
|
+
limit?: number;
|
|
208
210
|
}) => Promise<any[]>;
|
|
209
211
|
};
|
|
210
212
|
delete: {
|
|
@@ -237,6 +239,7 @@ declare class Client {
|
|
|
237
239
|
recordsWithIterator: (params: {
|
|
238
240
|
object_name: string;
|
|
239
241
|
ids: string[];
|
|
242
|
+
limit?: number;
|
|
240
243
|
}) => Promise<any[]>;
|
|
241
244
|
};
|
|
242
245
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -432,11 +432,11 @@ class Client {
|
|
|
432
432
|
/**
|
|
433
433
|
* 分批创建所有记录 - 支持超过 100 条数据,自动拆分
|
|
434
434
|
* @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
|
|
435
|
-
* @param params 请求参数 { object_name, records }
|
|
435
|
+
* @param params 请求参数 { object_name, records, limit }
|
|
436
436
|
* @returns { total, items }
|
|
437
437
|
*/
|
|
438
|
-
recordsWithIterator: async (params: { object_name: string; records: any[] }): Promise<{ total: number; items: any[] }> => {
|
|
439
|
-
const { object_name, records } = params;
|
|
438
|
+
recordsWithIterator: async (params: { object_name: string; records: any[]; limit?: number }): Promise<{ total: number; items: any[] }> => {
|
|
439
|
+
const { object_name, records, limit = 100 } = params;
|
|
440
440
|
|
|
441
441
|
// 参数校验
|
|
442
442
|
if (!records || !Array.isArray(records)) {
|
|
@@ -451,7 +451,7 @@ class Client {
|
|
|
451
451
|
|
|
452
452
|
let results: any[] = [];
|
|
453
453
|
let total = records.length;
|
|
454
|
-
const chunkSize =
|
|
454
|
+
const chunkSize = limit;
|
|
455
455
|
let page = 0;
|
|
456
456
|
|
|
457
457
|
const chunks: any[][] = [];
|
|
@@ -556,8 +556,8 @@ class Client {
|
|
|
556
556
|
* @param params 请求参数
|
|
557
557
|
* @returns 所有子请求的返回结果数组
|
|
558
558
|
*/
|
|
559
|
-
recordsWithIterator: async (params: { object_name: string; records: any[] }): Promise<any[]> => {
|
|
560
|
-
const { object_name, records } = params;
|
|
559
|
+
recordsWithIterator: async (params: { object_name: string; records: any[]; limit?: number }): Promise<any[]> => {
|
|
560
|
+
const { object_name, records, limit = 100 } = params;
|
|
561
561
|
|
|
562
562
|
// 参数校验
|
|
563
563
|
if (!records || !Array.isArray(records)) {
|
|
@@ -569,10 +569,8 @@ class Client {
|
|
|
569
569
|
this.log(LoggerLevel.warn, '[object.update.recordsWithIterator] Empty records array provided, returning empty result');
|
|
570
570
|
return [];
|
|
571
571
|
}
|
|
572
|
-
|
|
573
|
-
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
574
572
|
|
|
575
|
-
const chunkSize =
|
|
573
|
+
const chunkSize = limit;
|
|
576
574
|
const chunks: any[][] = [];
|
|
577
575
|
for (let i = 0; i < records.length; i += chunkSize) {
|
|
578
576
|
chunks.push(records.slice(i, i + chunkSize));
|
|
@@ -584,15 +582,18 @@ class Client {
|
|
|
584
582
|
for (const [index, chunk] of chunks.entries()) {
|
|
585
583
|
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
586
584
|
|
|
587
|
-
const res = await
|
|
588
|
-
|
|
585
|
+
const res = await this.object.update.records({
|
|
586
|
+
object_name,
|
|
587
|
+
records: chunk
|
|
588
|
+
});
|
|
589
589
|
|
|
590
|
-
|
|
590
|
+
if (res.code !== '0') {
|
|
591
|
+
this.log(LoggerLevel.error, `[object.update.recordsWithIterator] Error updating records: code=${res.code}, msg=${res.msg}`);
|
|
592
|
+
throw new Error(res.msg || `Update failed with code ${res.code}`);
|
|
593
|
+
}
|
|
591
594
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
return response.data;
|
|
595
|
-
});
|
|
595
|
+
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Chunk ${index + 1} completed: ${object_name}, code=${res.code}`);
|
|
596
|
+
this.log(LoggerLevel.trace, `[object.update.recordsWithIterator] Chunk ${index + 1} response: ${JSON.stringify(res)}`);
|
|
596
597
|
|
|
597
598
|
results.push(res);
|
|
598
599
|
}
|
|
@@ -666,8 +667,8 @@ class Client {
|
|
|
666
667
|
* @param params 请求参数
|
|
667
668
|
* @returns 所有子请求的返回结果数组
|
|
668
669
|
*/
|
|
669
|
-
recordsWithIterator: async (params: { object_name: string; ids: string[] }): Promise<any[]> => {
|
|
670
|
-
const { object_name, ids } = params;
|
|
670
|
+
recordsWithIterator: async (params: { object_name: string; ids: string[]; limit?: number }): Promise<any[]> => {
|
|
671
|
+
const { object_name, ids, limit = 100 } = params;
|
|
671
672
|
|
|
672
673
|
// 参数校验
|
|
673
674
|
if (!ids || !Array.isArray(ids)) {
|
|
@@ -682,7 +683,7 @@ class Client {
|
|
|
682
683
|
|
|
683
684
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
684
685
|
|
|
685
|
-
const chunkSize =
|
|
686
|
+
const chunkSize = limit;
|
|
686
687
|
const chunks: string[][] = [];
|
|
687
688
|
for (let i = 0; i < ids.length; i += chunkSize) {
|
|
688
689
|
chunks.push(ids.slice(i, i + chunkSize));
|