teambition-server-sdk
Advanced tools
Comparing version 0.0.2 to 0.0.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* 数据工厂,对数据进行加工、处理 | ||
* @class DataFactory | ||
*/ | ||
class DataFactory { | ||
@@ -7,2 +11,9 @@ constructor(raw) { | ||
} | ||
/** | ||
* 数据分片请求获取 | ||
* @param {function} job | ||
* @param {number} [capacity=200] | ||
* @returns {Promise<any>} | ||
* @memberof DataFactory | ||
*/ | ||
async JobSlice(job, capacity = 200) { | ||
@@ -12,2 +23,5 @@ if (!Array.isArray(this.raw)) { | ||
} | ||
if (typeof job !== 'function') { | ||
throw new Error('job must be a func'); | ||
} | ||
// 分片请求 | ||
@@ -17,6 +31,8 @@ const dataSize = this.raw.length; | ||
let result; | ||
let index = 0; | ||
let start = 0; | ||
let end = capacity; | ||
// 保证顺序性 | ||
while (true) { | ||
if (capacity >= dataSize) { | ||
result = await job(this.raw.slice(index)); | ||
if (end >= dataSize) { | ||
result = await job(this.raw.slice(start)); | ||
ret = ret.concat(result); | ||
@@ -26,6 +42,6 @@ break; | ||
else { | ||
result = await job(this.raw.slice(index, capacity)); | ||
result = await job(this.raw.slice(start, end)); | ||
ret = ret.concat(result); | ||
index = capacity; | ||
capacity += capacity; | ||
start = end; | ||
end = capacity + end; | ||
} | ||
@@ -32,0 +48,0 @@ } |
@@ -5,1 +5,3 @@ "use strict"; | ||
exports.DataFactory = datafactory_1.DataFactory; | ||
const interface_1 = require("./interface"); | ||
exports.Client = interface_1.default; |
{ | ||
"name": "teambition-server-sdk", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Javascript SDK for teambition server", | ||
@@ -22,2 +22,3 @@ "main": "lib/index.js", | ||
"@types/mocha": "^5.2.5", | ||
"@types/request-promise": "^4.1.42", | ||
"mocha": "^5.2.0", | ||
@@ -28,3 +29,6 @@ "should": "^13.2.3", | ||
"typescript": "^3.1.3" | ||
}, | ||
"dependencies": { | ||
"request-promise": "^4.2.2" | ||
} | ||
} |
## Teambition Server SDK | ||
Teambition 服务端 Node SDK,封装如下方法: | ||
- [ ] 数据处理: 常用的数据加工处理方法 | ||
- [ ] 官方 API: 常用的 `Teambition` 主站官方 API 封装,使用者不应该关注具体 URL 的变动 | ||
- [ ] 工具函数: 封装与 `Teambition` 强相关的业务需要使用到的工具函数 | ||
### 数据处理 | ||
**JobSlice(分片执行)** | ||
```js | ||
// JS Demo | ||
function request (sliceRaw) { | ||
// do anything | ||
} | ||
const raw = new Array(20) | ||
const datafactory = new TeambitionSDK.DataFactory(raw) | ||
datafactory.JobSlice(request) | ||
``` | ||
### 官方 API |
import { DataFactory } from './datafactory' | ||
import Client from './interface' | ||
export { | ||
DataFactory, | ||
Client | ||
} |
@@ -12,5 +12,4 @@ { | ||
"include": [ | ||
"src/**/*", | ||
"test/**/*" | ||
"src/**/*" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25989
23
340
24
1
7
+ Addedrequest-promise@^4.2.2
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrequest-promise@4.2.6(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstealthy-require@1.1.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)