apaas-oapi-client 0.1.23 → 0.1.25
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 +20 -11
- package/package.json +1 -1
- package/src/index.ts +21 -13
package/dist/index.js
CHANGED
|
@@ -169,12 +169,17 @@ class Client {
|
|
|
169
169
|
let total = 0;
|
|
170
170
|
let page = 0;
|
|
171
171
|
let totalPages = 0;
|
|
172
|
+
let hasMore = true;
|
|
172
173
|
const pageSize = data.page_size || 100;
|
|
173
|
-
|
|
174
|
+
while (hasMore) {
|
|
174
175
|
await functionLimiter(async () => {
|
|
175
176
|
var _a, _b, _c, _d;
|
|
176
177
|
const mergedData = { ...data };
|
|
177
|
-
|
|
178
|
+
// 如果使用 page_token,第一页需要传空字符串
|
|
179
|
+
if (data.use_page_token) {
|
|
180
|
+
mergedData.page_token = nextPageToken || '';
|
|
181
|
+
}
|
|
182
|
+
else if (nextPageToken) {
|
|
178
183
|
mergedData.page_token = nextPageToken;
|
|
179
184
|
}
|
|
180
185
|
const res = await this.object.search.records({
|
|
@@ -197,15 +202,17 @@ class Client {
|
|
|
197
202
|
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Starting paginated query: ${object_name}, total=${total}, pages=${totalPages}`);
|
|
198
203
|
}
|
|
199
204
|
nextPageToken = (_a = res.data) === null || _a === void 0 ? void 0 : _a.next_page_token;
|
|
205
|
+
// 检查是否还有更多数据:next_page_token 存在且不为空字符串
|
|
206
|
+
hasMore = !!(nextPageToken && nextPageToken !== '' && nextPageToken !== 'null');
|
|
200
207
|
const padLength = totalPages.toString().length;
|
|
201
208
|
const pageStr = page.toString().padStart(padLength, '0');
|
|
202
209
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
203
210
|
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
204
|
-
this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${(_c = (_b = res.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length}, nextToken=${nextPageToken || 'none'}`);
|
|
211
|
+
this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${(_c = (_b = res.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length}, nextToken=${nextPageToken || 'none'}, hasMore=${hasMore}`);
|
|
205
212
|
this.log(LoggerLevel.trace, `[object.search.recordsWithIterator] Page ${page} data: ${JSON.stringify((_d = res.data) === null || _d === void 0 ? void 0 : _d.items)}`);
|
|
206
213
|
return res;
|
|
207
214
|
});
|
|
208
|
-
}
|
|
215
|
+
}
|
|
209
216
|
return { total, items: results };
|
|
210
217
|
}
|
|
211
218
|
},
|
|
@@ -362,7 +369,6 @@ class Client {
|
|
|
362
369
|
this.log(LoggerLevel.warn, '[object.update.recordsWithIterator] Empty records array provided, returning empty result');
|
|
363
370
|
return [];
|
|
364
371
|
}
|
|
365
|
-
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
366
372
|
const chunkSize = 100;
|
|
367
373
|
const chunks = [];
|
|
368
374
|
for (let i = 0; i < records.length; i += chunkSize) {
|
|
@@ -372,13 +378,16 @@ class Client {
|
|
|
372
378
|
const results = [];
|
|
373
379
|
for (const [index, chunk] of chunks.entries()) {
|
|
374
380
|
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
375
|
-
const res = await
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Chunk ${index + 1} completed: ${object_name}, code=${response.data.code}`);
|
|
379
|
-
this.log(LoggerLevel.trace, `[object.update.recordsWithIterator] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
|
|
380
|
-
return response.data;
|
|
381
|
+
const res = await this.object.update.records({
|
|
382
|
+
object_name,
|
|
383
|
+
records: chunk
|
|
381
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)}`);
|
|
382
391
|
results.push(res);
|
|
383
392
|
}
|
|
384
393
|
return results;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -309,13 +309,17 @@ class Client {
|
|
|
309
309
|
let total = 0;
|
|
310
310
|
let page = 0;
|
|
311
311
|
let totalPages = 0;
|
|
312
|
+
let hasMore = true;
|
|
312
313
|
|
|
313
314
|
const pageSize = data.page_size || 100;
|
|
314
315
|
|
|
315
|
-
|
|
316
|
+
while (hasMore) {
|
|
316
317
|
const pageRes = await functionLimiter(async () => {
|
|
317
318
|
const mergedData: any = { ...data };
|
|
318
|
-
|
|
319
|
+
// 如果使用 page_token,第一页需要传空字符串
|
|
320
|
+
if (data.use_page_token) {
|
|
321
|
+
mergedData.page_token = nextPageToken || '';
|
|
322
|
+
} else if (nextPageToken) {
|
|
319
323
|
mergedData.page_token = nextPageToken;
|
|
320
324
|
}
|
|
321
325
|
|
|
@@ -345,18 +349,21 @@ class Client {
|
|
|
345
349
|
}
|
|
346
350
|
|
|
347
351
|
nextPageToken = res.data?.next_page_token;
|
|
352
|
+
|
|
353
|
+
// 检查是否还有更多数据:next_page_token 存在且不为空字符串
|
|
354
|
+
hasMore = !!(nextPageToken && nextPageToken !== '' && nextPageToken !== 'null');
|
|
348
355
|
|
|
349
356
|
const padLength = totalPages.toString().length;
|
|
350
357
|
const pageStr = page.toString().padStart(padLength, '0');
|
|
351
358
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
352
359
|
|
|
353
360
|
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
354
|
-
this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${res.data?.items?.length}, nextToken=${nextPageToken || 'none'}`);
|
|
361
|
+
this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${res.data?.items?.length}, nextToken=${nextPageToken || 'none'}, hasMore=${hasMore}`);
|
|
355
362
|
this.log(LoggerLevel.trace, `[object.search.recordsWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
356
363
|
|
|
357
364
|
return res;
|
|
358
365
|
});
|
|
359
|
-
}
|
|
366
|
+
}
|
|
360
367
|
|
|
361
368
|
return { total, items: results };
|
|
362
369
|
}
|
|
@@ -562,8 +569,6 @@ class Client {
|
|
|
562
569
|
this.log(LoggerLevel.warn, '[object.update.recordsWithIterator] Empty records array provided, returning empty result');
|
|
563
570
|
return [];
|
|
564
571
|
}
|
|
565
|
-
|
|
566
|
-
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
567
572
|
|
|
568
573
|
const chunkSize = 100;
|
|
569
574
|
const chunks: any[][] = [];
|
|
@@ -577,15 +582,18 @@ class Client {
|
|
|
577
582
|
for (const [index, chunk] of chunks.entries()) {
|
|
578
583
|
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
579
584
|
|
|
580
|
-
const res = await
|
|
581
|
-
|
|
585
|
+
const res = await this.object.update.records({
|
|
586
|
+
object_name,
|
|
587
|
+
records: chunk
|
|
588
|
+
});
|
|
582
589
|
|
|
583
|
-
|
|
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
|
+
}
|
|
584
594
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
return response.data;
|
|
588
|
-
});
|
|
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)}`);
|
|
589
597
|
|
|
590
598
|
results.push(res);
|
|
591
599
|
}
|