apaas-oapi-client 0.1.10 → 0.1.11

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.d.ts CHANGED
@@ -12,15 +12,6 @@ interface ClientOptions {
12
12
  /** 是否禁用 token 缓存, 每次调用强制刷新 token, 默认 false */
13
13
  disableTokenCache?: boolean;
14
14
  }
15
- /**
16
- * records_query 接口请求参数
17
- */
18
- interface RecordsQueryParams {
19
- /** 对象名称, 例如 object_store */
20
- object_name: string;
21
- /** 请求体数据 */
22
- data: any;
23
- }
24
15
  /**
25
16
  * aPaaS OpenAPI 客户端
26
17
  */
@@ -76,6 +67,7 @@ declare class Client {
76
67
  metadata: {
77
68
  /**
78
69
  * 获取指定对象下指定字段的元数据
70
+ * @description 查询指定对象下的单个字段元数据
79
71
  * @param params 请求参数 { object_name, field_name }
80
72
  * @returns 接口返回结果
81
73
  */
@@ -85,6 +77,7 @@ declare class Client {
85
77
  }) => Promise<any>;
86
78
  /**
87
79
  * 获取指定对象的所有字段信息
80
+ * @description 查询指定对象下的所有字段元数据
88
81
  * @param params 请求参数 { object_name }
89
82
  * @returns 接口返回结果
90
83
  */
@@ -95,6 +88,7 @@ declare class Client {
95
88
  search: {
96
89
  /**
97
90
  * 单条记录查询
91
+ * @description 查询指定对象下的单条记录
98
92
  * @param params 请求参数
99
93
  * @returns 接口返回结果
100
94
  */
@@ -104,17 +98,25 @@ declare class Client {
104
98
  select: string[];
105
99
  }) => Promise<any>;
106
100
  /**
107
- * records_query 接口
101
+ * 多条记录查询 - 最多传入 100 条
102
+ * @description 查询指定对象下的多条记录
108
103
  * @param params 请求参数
109
104
  * @returns 接口返回结果
110
105
  */
111
- records: (params: RecordsQueryParams) => Promise<any>;
106
+ records: (params: {
107
+ object_name: string;
108
+ data: any;
109
+ }) => Promise<any>;
112
110
  /**
113
- * 分页查询所有记录
111
+ * 查询所有记录 - 支持超过 100 条数据,自动分页查询
112
+ * @description 该方法会自动处理分页,直到没有更多数据为止
114
113
  * @param params 请求参数
115
114
  * @returns { total, items }
116
115
  */
117
- recordsWithIterator: (params: RecordsQueryParams) => Promise<{
116
+ recordsWithIterator: (params: {
117
+ object_name: string;
118
+ data: any;
119
+ }) => Promise<{
118
120
  total: number;
119
121
  items: any[];
120
122
  }>;
@@ -122,6 +124,7 @@ declare class Client {
122
124
  create: {
123
125
  /**
124
126
  * 单条记录创建
127
+ * @description 创建单条记录到指定对象中
125
128
  * @param params 请求参数 { object_name, record }
126
129
  * @returns 接口返回结果
127
130
  */
@@ -130,7 +133,8 @@ declare class Client {
130
133
  record: any;
131
134
  }) => Promise<any>;
132
135
  /**
133
- * 批量创建记录
136
+ * 批量创建记录 - 最多传入 100 条
137
+ * @description 创建多条记录到指定对象中
134
138
  * @param params 请求参数 { object_name, records }
135
139
  * @returns 接口返回结果
136
140
  */
@@ -139,7 +143,8 @@ declare class Client {
139
143
  records: any[];
140
144
  }) => Promise<any>;
141
145
  /**
142
- * 分批创建所有记录
146
+ * 分批创建所有记录 - 支持超过 100 条数据,自动拆分
147
+ * @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
143
148
  * @param params 请求参数 { object_name, records }
144
149
  * @returns { total, items }
145
150
  */
@@ -154,6 +159,7 @@ declare class Client {
154
159
  update: {
155
160
  /**
156
161
  * 单条更新
162
+ * @description 更新指定对象下的单条记录
157
163
  * @param params 请求参数
158
164
  * @returns 接口返回结果
159
165
  */
@@ -163,11 +169,22 @@ declare class Client {
163
169
  record: any;
164
170
  }) => Promise<any>;
165
171
  /**
166
- * 批量更新
172
+ * 多条更新 - 最多传入 100 条
173
+ * @description 更新指定对象下的多条记录
174
+ * @param params 请求参数
175
+ * @returns 接口返回结果
176
+ */
177
+ records: (params: {
178
+ object_name: string;
179
+ records: any[];
180
+ }) => Promise<any>;
181
+ /**
182
+ * 批量更新 - 支持超过 100 条数据,自动拆分
183
+ * @description 更新指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
167
184
  * @param params 请求参数
168
185
  * @returns 所有子请求的返回结果数组
169
186
  */
170
- recordsBatchUpdate: (params: {
187
+ recordsWithIterator: (params: {
171
188
  object_name: string;
172
189
  records: any[];
173
190
  }) => Promise<any[]>;
@@ -175,6 +192,7 @@ declare class Client {
175
192
  delete: {
176
193
  /**
177
194
  * 单条删除
195
+ * @description 删除指定对象下的单条记录
178
196
  * @param params 请求参数
179
197
  * @returns 接口返回结果
180
198
  */
@@ -182,12 +200,23 @@ declare class Client {
182
200
  object_name: string;
183
201
  record_id: string;
184
202
  }) => Promise<any>;
203
+ /**
204
+ * 多条删除 - 最多传入 100 条
205
+ * @description 删除指定对象下的多条记录
206
+ * @param params 请求参数
207
+ * @returns 接口返回结果
208
+ */
209
+ records: (params: {
210
+ object_name: string;
211
+ ids: string[];
212
+ }) => Promise<any>;
185
213
  /**
186
214
  * 批量删除
215
+ * @description 删除指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
187
216
  * @param params 请求参数
188
217
  * @returns 所有子请求的返回结果数组
189
218
  */
190
- recordsBatchDelete: (params: {
219
+ recordsWithIterator: (params: {
191
220
  object_name: string;
192
221
  ids: string[];
193
222
  }) => Promise<any[]>;
package/dist/index.js CHANGED
@@ -62,6 +62,7 @@ class Client {
62
62
  metadata: {
63
63
  /**
64
64
  * 获取指定对象下指定字段的元数据
65
+ * @description 查询指定对象下的单个字段元数据
65
66
  * @param params 请求参数 { object_name, field_name }
66
67
  * @returns 接口返回结果
67
68
  */
@@ -79,6 +80,7 @@ class Client {
79
80
  },
80
81
  /**
81
82
  * 获取指定对象的所有字段信息
83
+ * @description 查询指定对象下的所有字段元数据
82
84
  * @param params 请求参数 { object_name }
83
85
  * @returns 接口返回结果
84
86
  */
@@ -98,6 +100,7 @@ class Client {
98
100
  search: {
99
101
  /**
100
102
  * 单条记录查询
103
+ * @description 查询指定对象下的单条记录
101
104
  * @param params 请求参数
102
105
  * @returns 接口返回结果
103
106
  */
@@ -115,7 +118,8 @@ class Client {
115
118
  return res;
116
119
  },
117
120
  /**
118
- * records_query 接口
121
+ * 多条记录查询 - 最多传入 100 条
122
+ * @description 查询指定对象下的多条记录
119
123
  * @param params 请求参数
120
124
  * @returns 接口返回结果
121
125
  */
@@ -133,7 +137,8 @@ class Client {
133
137
  return res.data;
134
138
  },
135
139
  /**
136
- * 分页查询所有记录
140
+ * 查询所有记录 - 支持超过 100 条数据,自动分页查询
141
+ * @description 该方法会自动处理分页,直到没有更多数据为止
137
142
  * @param params 请求参数
138
143
  * @returns { total, items }
139
144
  */
@@ -171,6 +176,7 @@ class Client {
171
176
  create: {
172
177
  /**
173
178
  * 单条记录创建
179
+ * @description 创建单条记录到指定对象中
174
180
  * @param params 请求参数 { object_name, record }
175
181
  * @returns 接口返回结果
176
182
  */
@@ -191,7 +197,8 @@ class Client {
191
197
  return res;
192
198
  },
193
199
  /**
194
- * 批量创建记录
200
+ * 批量创建记录 - 最多传入 100 条
201
+ * @description 创建多条记录到指定对象中
195
202
  * @param params 请求参数 { object_name, records }
196
203
  * @returns 接口返回结果
197
204
  */
@@ -208,7 +215,8 @@ class Client {
208
215
  return res.data;
209
216
  },
210
217
  /**
211
- * 分批创建所有记录
218
+ * 分批创建所有记录 - 支持超过 100 条数据,自动拆分
219
+ * @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
212
220
  * @param params 请求参数 { object_name, records }
213
221
  * @returns { total, items }
214
222
  */
@@ -248,6 +256,7 @@ class Client {
248
256
  update: {
249
257
  /**
250
258
  * 单条更新
259
+ * @description 更新指定对象下的单条记录
251
260
  * @param params 请求参数
252
261
  * @returns 接口返回结果
253
262
  */
@@ -266,11 +275,28 @@ class Client {
266
275
  return res;
267
276
  },
268
277
  /**
269
- * 批量更新
278
+ * 多条更新 - 最多传入 100 条
279
+ * @description 更新指定对象下的多条记录
280
+ * @param params 请求参数
281
+ * @returns 接口返回结果
282
+ */
283
+ records: async (params) => {
284
+ const { object_name, records } = params;
285
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
286
+ this.log(LoggerLevel.info, `[多条更新记录] 💾 开始更新 ${records.length} 条数据`);
287
+ const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
288
+ this.log(LoggerLevel.info, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成`);
289
+ this.log(LoggerLevel.debug, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回状态: ${response.data.code}`);
290
+ this.log(LoggerLevel.trace, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
291
+ return response.data;
292
+ },
293
+ /**
294
+ * 批量更新 - 支持超过 100 条数据,自动拆分
295
+ * @description 更新指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
270
296
  * @param params 请求参数
271
297
  * @returns 所有子请求的返回结果数组
272
298
  */
273
- recordsBatchUpdate: async (params) => {
299
+ recordsWithIterator: async (params) => {
274
300
  const { object_name, records } = params;
275
301
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
276
302
  const chunkSize = 100;
@@ -299,6 +325,7 @@ class Client {
299
325
  delete: {
300
326
  /**
301
327
  * 单条删除
328
+ * @description 删除指定对象下的单条记录
302
329
  * @param params 请求参数
303
330
  * @returns 接口返回结果
304
331
  */
@@ -316,12 +343,36 @@ class Client {
316
343
  });
317
344
  return res;
318
345
  },
346
+ /**
347
+ * 多条删除 - 最多传入 100 条
348
+ * @description 删除指定对象下的多条记录
349
+ * @param params 请求参数
350
+ * @returns 接口返回结果
351
+ */
352
+ records: async (params) => {
353
+ const { object_name, ids } = params;
354
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
355
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除对象 ${object_name} 的 ${ids.length} 条记录`);
356
+ const res = await functionLimiter(async () => {
357
+ await this.ensureTokenValid();
358
+ const response = await this.axiosInstance.delete(url, {
359
+ data: { ids },
360
+ headers: { Authorization: `${this.accessToken}`, 'Content-Type': 'application/json' }
361
+ });
362
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成`);
363
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回状态: ${response.data.code}`);
364
+ this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回信息: ${JSON.stringify(response.data)}`);
365
+ return response.data;
366
+ });
367
+ return res;
368
+ },
319
369
  /**
320
370
  * 批量删除
371
+ * @description 删除指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
321
372
  * @param params 请求参数
322
373
  * @returns 所有子请求的返回结果数组
323
374
  */
324
- recordsBatchDelete: async (params) => {
375
+ recordsWithIterator: async (params) => {
325
376
  const { object_name, ids } = params;
326
377
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
327
378
  const chunkSize = 100;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "main": "dist/index.js",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
package/src/index.ts CHANGED
@@ -29,16 +29,6 @@ interface TokenResponse {
29
29
  msg: string;
30
30
  }
31
31
 
32
- /**
33
- * records_query 接口请求参数
34
- */
35
- interface RecordsQueryParams {
36
- /** 对象名称, 例如 object_store */
37
- object_name: string;
38
- /** 请求体数据 */
39
- data: any;
40
- }
41
-
42
32
  /**
43
33
  * aPaaS OpenAPI 客户端
44
34
  */
@@ -164,6 +154,7 @@ class Client {
164
154
  metadata: {
165
155
  /**
166
156
  * 获取指定对象下指定字段的元数据
157
+ * @description 查询指定对象下的单个字段元数据
167
158
  * @param params 请求参数 { object_name, field_name }
168
159
  * @returns 接口返回结果
169
160
  */
@@ -185,6 +176,7 @@ class Client {
185
176
 
186
177
  /**
187
178
  * 获取指定对象的所有字段信息
179
+ * @description 查询指定对象下的所有字段元数据
188
180
  * @param params 请求参数 { object_name }
189
181
  * @returns 接口返回结果
190
182
  */
@@ -208,6 +200,7 @@ class Client {
208
200
  search: {
209
201
  /**
210
202
  * 单条记录查询
203
+ * @description 查询指定对象下的单条记录
211
204
  * @param params 请求参数
212
205
  * @returns 接口返回结果
213
206
  */
@@ -232,11 +225,12 @@ class Client {
232
225
  },
233
226
 
234
227
  /**
235
- * records_query 接口
228
+ * 多条记录查询 - 最多传入 100 条
229
+ * @description 查询指定对象下的多条记录
236
230
  * @param params 请求参数
237
231
  * @returns 接口返回结果
238
232
  */
239
- records: async (params: RecordsQueryParams): Promise<any> => {
233
+ records: async (params: { object_name: string; data: any }): Promise<any> => {
240
234
  const { object_name, data } = params;
241
235
  await this.ensureTokenValid();
242
236
 
@@ -253,11 +247,12 @@ class Client {
253
247
  },
254
248
 
255
249
  /**
256
- * 分页查询所有记录
250
+ * 查询所有记录 - 支持超过 100 条数据,自动分页查询
251
+ * @description 该方法会自动处理分页,直到没有更多数据为止
257
252
  * @param params 请求参数
258
253
  * @returns { total, items }
259
254
  */
260
- recordsWithIterator: async (params: RecordsQueryParams): Promise<{ total: number; items: any[] }> => {
255
+ recordsWithIterator: async (params: { object_name: string; data: any }): Promise<{ total: number; items: any[] }> => {
261
256
  const { object_name, data } = params;
262
257
 
263
258
  let results: any[] = [];
@@ -301,6 +296,7 @@ class Client {
301
296
  create: {
302
297
  /**
303
298
  * 单条记录创建
299
+ * @description 创建单条记录到指定对象中
304
300
  * @param params 请求参数 { object_name, record }
305
301
  * @returns 接口返回结果
306
302
  */
@@ -332,7 +328,8 @@ class Client {
332
328
  },
333
329
 
334
330
  /**
335
- * 批量创建记录
331
+ * 批量创建记录 - 最多传入 100 条
332
+ * @description 创建多条记录到指定对象中
336
333
  * @param params 请求参数 { object_name, records }
337
334
  * @returns 接口返回结果
338
335
  */
@@ -357,7 +354,8 @@ class Client {
357
354
  },
358
355
 
359
356
  /**
360
- * 分批创建所有记录
357
+ * 分批创建所有记录 - 支持超过 100 条数据,自动拆分
358
+ * @description 创建多条记录到指定对象中,超过 100 条数据会自动拆分为多次请求
361
359
  * @param params 请求参数 { object_name, records }
362
360
  * @returns { total, items }
363
361
  */
@@ -408,6 +406,7 @@ class Client {
408
406
  update: {
409
407
  /**
410
408
  * 单条更新
409
+ * @description 更新指定对象下的单条记录
411
410
  * @param params 请求参数
412
411
  * @returns 接口返回结果
413
412
  */
@@ -432,11 +431,33 @@ class Client {
432
431
  },
433
432
 
434
433
  /**
435
- * 批量更新
434
+ * 多条更新 - 最多传入 100 条
435
+ * @description 更新指定对象下的多条记录
436
+ * @param params 请求参数
437
+ * @returns 接口返回结果
438
+ */
439
+ records: async (params: { object_name: string; records: any[] }): Promise<any> => {
440
+ const { object_name, records } = params;
441
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
442
+
443
+ this.log(LoggerLevel.info, `[多条更新记录] 💾 开始更新 ${records.length} 条数据`);
444
+
445
+ const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
446
+
447
+ this.log(LoggerLevel.info, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成`);
448
+ this.log(LoggerLevel.debug, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回状态: ${response.data.code}`);
449
+ this.log(LoggerLevel.trace, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
450
+
451
+ return response.data;
452
+ },
453
+
454
+ /**
455
+ * 批量更新 - 支持超过 100 条数据,自动拆分
456
+ * @description 更新指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
436
457
  * @param params 请求参数
437
458
  * @returns 所有子请求的返回结果数组
438
459
  */
439
- recordsBatchUpdate: async (params: { object_name: string; records: any[] }): Promise<any[]> => {
460
+ recordsWithIterator: async (params: { object_name: string; records: any[] }): Promise<any[]> => {
440
461
  const { object_name, records } = params;
441
462
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
442
463
 
@@ -474,6 +495,7 @@ class Client {
474
495
  delete: {
475
496
  /**
476
497
  * 单条删除
498
+ * @description 删除指定对象下的单条记录
477
499
  * @param params 请求参数
478
500
  * @returns 接口返回结果
479
501
  */
@@ -497,12 +519,43 @@ class Client {
497
519
  return res;
498
520
  },
499
521
 
522
+ /**
523
+ * 多条删除 - 最多传入 100 条
524
+ * @description 删除指定对象下的多条记录
525
+ * @param params 请求参数
526
+ * @returns 接口返回结果
527
+ */
528
+ records: async (params: { object_name: string; ids: string[] }): Promise<any> => {
529
+ const { object_name, ids } = params;
530
+ const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
531
+
532
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除对象 ${object_name} 的 ${ids.length} 条记录`);
533
+
534
+ const res = await functionLimiter(async () => {
535
+ await this.ensureTokenValid();
536
+
537
+ const response = await this.axiosInstance.delete(url, {
538
+ data: { ids },
539
+ headers: { Authorization: `${this.accessToken}`, 'Content-Type': 'application/json' }
540
+ });
541
+
542
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成`);
543
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回状态: ${response.data.code}`);
544
+ this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回信息: ${JSON.stringify(response.data)}`);
545
+
546
+ return response.data;
547
+ });
548
+
549
+ return res;
550
+ },
551
+
500
552
  /**
501
553
  * 批量删除
554
+ * @description 删除指定对象下的多条记录,超过 100 条数据会自动拆分为多次请求
502
555
  * @param params 请求参数
503
556
  * @returns 所有子请求的返回结果数组
504
557
  */
505
- recordsBatchDelete: async (params: { object_name: string; ids: string[] }): Promise<any[]> => {
558
+ recordsWithIterator: async (params: { object_name: string; ids: string[] }): Promise<any[]> => {
506
559
  const { object_name, ids } = params;
507
560
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
508
561