apaas-oapi-client 0.1.14 → 0.1.15

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.
Files changed (3) hide show
  1. package/dist/index.js +15 -12
  2. package/package.json +1 -1
  3. package/src/index.ts +14 -12
package/dist/index.js CHANGED
@@ -148,14 +148,15 @@ class Client {
148
148
  let nextPageToken = '';
149
149
  let total = 0;
150
150
  let page = 0;
151
- const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_query`;
151
+ let totalPages = 0;
152
+ const pageSize = data.page_size || 100;
152
153
  do {
153
154
  await functionLimiter(async () => {
154
- var _a, _b, _c;
155
+ var _a, _b;
155
156
  const mergedData = { ...data, page_token: nextPageToken || '' };
156
- await this.ensureTokenValid();
157
- const res = await this.axiosInstance.post(url, mergedData, {
158
- headers: { Authorization: `${this.accessToken}` }
157
+ const res = await this.object.search.records({
158
+ object_name,
159
+ data: mergedData
159
160
  });
160
161
  page += 1;
161
162
  if (res.data && Array.isArray(res.data.items)) {
@@ -163,15 +164,17 @@ class Client {
163
164
  }
164
165
  if (page === 1) {
165
166
  total = res.data.total || 0;
166
- this.log(LoggerLevel.info, `[批量查询记录] 🔍 object_name=${object_name}, 接口返回 total: ${total}`);
167
+ totalPages = Math.ceil(total / pageSize);
168
+ this.log(LoggerLevel.info, `[批量查询记录] 🔍 查询 object_name=${object_name}, 接口返回 total=${total}, 预计 ${totalPages} 页`);
167
169
  }
168
- const totalPages = Math.ceil(total / (data.page_size || 100));
169
- const padLength = String(totalPages).length;
170
- this.log(LoggerLevel.info, `[批量查询记录] 🔍 [${String(page).padStart(padLength, '0')}/${totalPages}] 接口调用完成`);
171
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${((_a = res.data) === null || _a === void 0 ? void 0 : _a.next_page_token) || ''}`);
172
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成, items.length: ${(_b = res.data.items) === null || _b === void 0 ? void 0 : _b.length}`);
173
- this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify((_c = res.data) === null || _c === void 0 ? void 0 : _c.items)}`);
174
170
  nextPageToken = res.data.next_page_token;
171
+ const padLength = totalPages.toString().length;
172
+ const pageStr = page.toString().padStart(padLength, '0');
173
+ const totalPagesStr = totalPages.toString().padStart(padLength, '0');
174
+ this.log(LoggerLevel.info, `[批量查询记录] 🔍 [${pageStr}/${totalPagesStr}] 接口调用完成`);
175
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${nextPageToken || ''}`);
176
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成, items.length: ${(_a = res.data.items) === null || _a === void 0 ? void 0 : _a.length}`);
177
+ this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify((_b = res.data) === null || _b === void 0 ? void 0 : _b.items)}`);
175
178
  return res;
176
179
  });
177
180
  } while (nextPageToken);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "main": "dist/index.js",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
package/src/index.ts CHANGED
@@ -283,17 +283,17 @@ class Client {
283
283
  let nextPageToken: string | undefined = '';
284
284
  let total = 0;
285
285
  let page = 0;
286
+ let totalPages = 0;
286
287
 
287
- const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_query`;
288
+ const pageSize = data.page_size || 100;
288
289
 
289
290
  do {
290
291
  const pageRes = await functionLimiter(async () => {
291
292
  const mergedData = { ...data, page_token: nextPageToken || '' };
292
293
 
293
- await this.ensureTokenValid();
294
-
295
- const res = await this.axiosInstance.post(url, mergedData, {
296
- headers: { Authorization: `${this.accessToken}` }
294
+ const res = await this.object.search.records({
295
+ object_name,
296
+ data: mergedData
297
297
  });
298
298
 
299
299
  page += 1;
@@ -304,19 +304,21 @@ class Client {
304
304
 
305
305
  if (page === 1) {
306
306
  total = res.data.total || 0;
307
- this.log(LoggerLevel.info, `[批量查询记录] 🔍 object_name=${object_name}, 接口返回 total: ${total}`);
307
+ totalPages = Math.ceil(total / pageSize);
308
+ this.log(LoggerLevel.info, `[批量查询记录] 🔍 查询 object_name=${object_name}, 接口返回 total=${total}, 预计 ${totalPages} 页`);
308
309
  }
309
310
 
310
- const totalPages = Math.ceil(total / (data.page_size || 100));
311
- const padLength = String(totalPages).length;
311
+ nextPageToken = res.data.next_page_token;
312
+
313
+ const padLength = totalPages.toString().length;
314
+ const pageStr = page.toString().padStart(padLength, '0');
315
+ const totalPagesStr = totalPages.toString().padStart(padLength, '0');
312
316
 
313
- this.log(LoggerLevel.info, `[批量查询记录] 🔍 [${String(page).padStart(padLength, '0')}/${totalPages}] 接口调用完成`);
314
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${res.data?.next_page_token || ''}`);
317
+ this.log(LoggerLevel.info, `[批量查询记录] 🔍 [${pageStr}/${totalPagesStr}] 接口调用完成`);
318
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${nextPageToken || ''}`);
315
319
  this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成, items.length: ${res.data.items?.length}`);
316
320
  this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify(res.data?.items)}`);
317
321
 
318
- nextPageToken = res.data.next_page_token;
319
-
320
322
  return res;
321
323
  });
322
324
  } while (nextPageToken);