apaas-oapi-client 0.1.7 → 0.1.9

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 CHANGED
@@ -7,8 +7,10 @@ aPaaS 平台有完整的 Open API 能力,但是目前这些能力全都以单
7
7
 
8
8
  - ✅ 获取 accessToken,自动管理 token 有效期
9
9
 
10
- - ✅ record 单条查询、 records 记录列表查询(支持分页迭代)
11
-
10
+ - ✅ record 单条查询、批量查询(支持分页迭代)
11
+
12
+ - ✅ record 单条创建、批量创建(支持分页迭代)
13
+
12
14
  - ✅ record 单条更新、批量更新
13
15
 
14
16
  - ✅ record 单条删除、批量删除
@@ -151,6 +153,42 @@ console.log('Items:', items);
151
153
 
152
154
  <br>
153
155
 
156
+
157
+ ***
158
+
159
+ ## **➕ 创建接口**
160
+
161
+ ### **单条创建**
162
+
163
+ ```JavaScript
164
+ const res = await client.object.create.record({
165
+ object_name: 'object_event_log',
166
+ record: {
167
+ name: 'Sample text',
168
+ content: 'Sample text'
169
+ }
170
+ });
171
+ console.log(res);
172
+ ```
173
+
174
+ ### **批量创建**
175
+
176
+ > ⚠️ 每次最多创建 100 条,SDK 已自动分组限流
177
+
178
+ ```JavaScript
179
+ const { total, items } = await client.object.create.recordsWithIterator({
180
+ object_name: 'object_event_log',
181
+ records: [
182
+ { name: 'Sample text 1', content: 'Sample text 1' },
183
+ { name: 'Sample text 2', content: 'Sample text 2' }
184
+ ]
185
+ });
186
+ console.log('Total:', total);
187
+ console.log('Items:', items);
188
+ ```
189
+
190
+
191
+ <br>
154
192
  ## **✏️ 更新接口**
155
193
 
156
194
  ### **单条更新**
@@ -248,4 +286,66 @@ console.log(client.currentNamespace);
248
286
 
249
287
  > 由 [aPaaS OAPI Client SDK](https://www.npmjs.com/package/apaas-oapi-client) 提供支持,如有问题请提交 Issue 反馈。
250
288
 
251
- <br>
289
+ <br>
290
+ ***
291
+
292
+ ## **📊 对象元数据接口**
293
+
294
+ ### **获取指定对象字段元数据**
295
+
296
+ ```JavaScript
297
+ const res = await client.object.metadata.field({
298
+ object_name: '_user',
299
+ field_name: '_id'
300
+ });
301
+ console.log(res);
302
+ ```
303
+
304
+ ### **获取指定对象所有字段信息**
305
+
306
+ ```JavaScript
307
+ const res = await client.object.metadata.fields({
308
+ object_name: 'object_store'
309
+ });
310
+ console.log(res);
311
+ ```
312
+
313
+ ***
314
+
315
+ ## **🏢 部门 ID 交换**
316
+
317
+ ### **单个部门 ID 交换**
318
+
319
+ ```JavaScript
320
+ const res = await client.department.exchange({
321
+ department_id_type: 'external_department_id',
322
+ department_id: 'Y806608904'
323
+ });
324
+ console.log(res);
325
+ ```
326
+
327
+ ### **批量部门 ID 交换**
328
+
329
+ 每次最多 100 个,SDK 已自动拆分限流。
330
+
331
+ ```JavaScript
332
+ const res = await client.department.batchExchange({
333
+ department_id_type: 'external_department_id',
334
+ department_ids: ['id1', 'id2', 'id3']
335
+ });
336
+ console.log(res);
337
+ ```
338
+
339
+ ***
340
+
341
+ ## **☁️ 云函数调用**
342
+
343
+ ```JavaScript
344
+ const res = await client.function.invoke({
345
+ name: 'StoreMemberUpdate',
346
+ params: { key: 'value' }
347
+ });
348
+ console.log(res);
349
+ ```
350
+
351
+ ---
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var dayjs = require('dayjs');
4
4
  var axios = require('axios');
5
+ var Bottleneck = require('bottleneck');
5
6
 
6
7
  /**
7
8
  * 日志等级枚举
@@ -16,7 +17,32 @@ var LoggerLevel;
16
17
  LoggerLevel[LoggerLevel["trace"] = 5] = "trace";
17
18
  })(LoggerLevel || (LoggerLevel = {}));
18
19
 
19
- const { functionLimiter } = require('./limiter');
20
+ /**
21
+ * 默认 apaas 限流配置
22
+ */
23
+ const apaasLimiterOptions = {
24
+ minTime: 200, // 每秒最多发起 5 个数据库操作
25
+ reservoir: 20, // 最多同时查询 50 个数据库操作
26
+ reservoirRefreshAmount: 20, // 每次查询完毕后,重置为 50 个数据库操作
27
+ reservoirRefreshInterval: 1000 // 重置时间间隔为 1 秒
28
+ };
29
+ /**
30
+ * 创建限流器
31
+ * @param fn 被限流函数
32
+ * @param options 自定义限流配置
33
+ * @returns 包装后的限流函数
34
+ */
35
+ async function functionLimiter(fn, options = {}) {
36
+ const limiter = new Bottleneck({
37
+ minTime: options.minTime || apaasLimiterOptions.minTime,
38
+ reservoir: options.reservoir || apaasLimiterOptions.reservoir,
39
+ reservoirRefreshAmount: options.reservoirRefreshAmount || apaasLimiterOptions.reservoirRefreshAmount,
40
+ reservoirRefreshInterval: options.reservoirRefreshInterval || apaasLimiterOptions.reservoirRefreshInterval
41
+ });
42
+ const wrapped = limiter.wrap(fn);
43
+ return wrapped();
44
+ }
45
+
20
46
  /**
21
47
  * aPaaS OpenAPI 客户端
22
48
  */
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
+ "main": "dist/index.js",
4
5
  "exports": {
6
+ ".": "./dist/index.js",
5
7
  "./node-sdk": "./dist/index.js"
6
8
  },
7
- "main": "dist/index.js",
8
9
  "types": "dist/index.d.ts",
9
10
  "type": "commonjs",
10
11
  "scripts": {
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import dayjs from 'dayjs';
2
2
  import axios, { AxiosInstance } from 'axios';
3
3
  import { LoggerLevel } from './logger';
4
- const { functionLimiter } = require('./limiter');
4
+ import { functionLimiter } from './limiter';
5
5
 
6
6
  /**
7
7
  * Client 初始化配置