tb-apps-sdk
Advanced tools
Comparing version 0.6.0-alpha.7-reportApp.0 to 0.6.0
@@ -10,2 +10,3 @@ import { AppSDK } from '../sdk'; | ||
export declare function factory<T>(sdk: AppSDK, ctor: ICtor<T>): T & IAPIBase; | ||
export declare function method(name: string): (...params: any[]) => any; | ||
export declare class APIBase { | ||
@@ -12,0 +13,0 @@ private sdk; |
@@ -7,2 +7,12 @@ "use strict"; | ||
exports.factory = factory; | ||
function method(name) { | ||
return function () { | ||
var params = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
params[_i] = arguments[_i]; | ||
} | ||
return this.call.apply(this, [name].concat(params)); | ||
}; | ||
} | ||
exports.method = method; | ||
var APIBase = /** @class */ (function () { | ||
@@ -9,0 +19,0 @@ // version: number = 0 |
@@ -5,1 +5,2 @@ export declare const ProcedureTimeout = "Procedure call time out."; | ||
export declare const IncorrectVersion = "API version doest not matched."; | ||
export declare const Uninitlized = "SDK should be initlized."; |
@@ -7,1 +7,2 @@ "use strict"; | ||
exports.IncorrectVersion = 'API version doest not matched.'; | ||
exports.Uninitlized = 'SDK should be initlized.'; |
{ | ||
"name": "tb-apps-sdk", | ||
"version": "0.6.0-alpha.7-reportApp.0", | ||
"version": "0.6.0", | ||
"description": "A sdk for communications between teambiton web and other envs.", | ||
"main": "./index.js", | ||
"scripts": { | ||
"precommit": "lint-staged", | ||
"build": "rm -rf ./lib && tsc -p ./tsconfig.json", | ||
"publish_sdk": "npm run build && cp README.md package.json ./lib && npm publish ./lib", | ||
"lint": "tslint -c tslint.json src/*.ts --project ./tsconfig.json \"src/**/*.ts\" \"./test/**/*.ts\" -e \"./test/e2e/*.ts\"" | ||
"cover": "rm -rf ./coverage ./.nyc_output && nyc --reporter=html --reporter=lcov --exclude=node_modules --exclude=test --exclude=lib/api/* --exclude=lib/call-service.js mocha && nyc report", | ||
"lint": "tslint -c tslint.json src/*.ts --project ./tsconfig.json \"src/**/*.ts\" \"./test/**/*.ts\" -e \"./test/e2e/*.ts\"", | ||
"test": "mocha" | ||
}, | ||
@@ -27,7 +30,32 @@ "typings": "index.d.ts", | ||
"devDependencies": { | ||
"typescript": "^2.8.3", | ||
"@types/chai": "^4.1.3", | ||
"@types/mocha": "^5.2.1", | ||
"chai": "^4.1.2", | ||
"coveralls": "^3.0.1", | ||
"lint-staged": "^7.2.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^12.0.2", | ||
"prettier": "^1.13.5", | ||
"sinon": "^6.0.0", | ||
"sinon-chai": "^3.1.0", | ||
"tslib": "^1.6.0", | ||
"tslint": "^5.9.1", | ||
"tslint-eslint-rules": "^5.1.0" | ||
"tslint-eslint-rules": "^5.1.0", | ||
"typescript": "^2.8.3" | ||
}, | ||
"prettier": { | ||
"printWidth": 120, | ||
"semi": false, | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"arrowParens": "always", | ||
"parser": "typescript" | ||
}, | ||
"lint-staged": { | ||
"*.ts": [ | ||
"prettier --write", | ||
"tslint -c tslint.json -p tsconfig.json --fix -e \"**/test/expect/**\"", | ||
"git add" | ||
] | ||
} | ||
} |
@@ -0,1 +1,4 @@ | ||
[](https://coveralls.io/github/teambition/tb-apps-sdk?branch=refactor/typescript) | ||
[](https://circleci.com/gh/teambition/tb-apps-sdk) | ||
# tb-apps-sdk | ||
@@ -99,13 +102,13 @@ | ||
- ```Static Method: AppSDK.fork(service, onPush, timeout)``` | ||
- ```Static Method: AppSDK.fork<T, K>(service, onPush, requestTimeout, connectTimeout)``` | ||
| 属性 | 说明 | 类型 | 默认值 | | ||
| - | - | - | - | | ||
| service | 指定装载的宿主 API 配置容器 | (sdk: AppSDK) => any | - | | ||
| onPush | 指定宿主环境主动推送时的回调 | (data: any) => void | - | | ||
| timeout | 指定远端调用最大超时时间 | number | 10000 | | ||
| service | 指定装载的宿主 API 配置容器 | (sdk: AppSDK) => T | - | | ||
| onPush | 指定宿主环境主动推送时的回调 | (data: K) => void | - | | ||
| requestTimeout | 指定远端调用最大超时时间 | number | 10000 | | ||
| connectTimeout | 指定远端连接最大超时时间 | number | 60000 | | ||
## License | ||
MIT | ||
@@ -6,3 +6,3 @@ import { RemoteCall } from '../interface'; | ||
private connectTimeout; | ||
static fork<T, K = any>(service: (sdk: AppSDK) => T, onPush?: (data: K) => void, timeout?: number): T; | ||
static fork<T, K = any>(service: (sdk: AppSDK) => T, onPush?: (data: K) => void, requestTimeout?: number, connectTimeout?: number): T; | ||
private procedures; | ||
@@ -20,3 +20,3 @@ private requestId; | ||
destroy(): void; | ||
send<T>(req: RemoteCall, isIsolated?: boolean): Promise<T>; | ||
send<T>(req: RemoteCall, isIsolated: boolean): Promise<T>; | ||
private onMessage; | ||
@@ -23,0 +23,0 @@ private serialize(payload?); |
@@ -28,2 +28,3 @@ "use strict"; | ||
case interface_1.MessageType.SYN: | ||
/* istanbul ignore else */ | ||
if (!_this.initialize) { | ||
@@ -40,2 +41,3 @@ _this.targetId = resp.data.targetId; | ||
case interface_1.MessageType.PSH: | ||
/* istanbul ignore else */ | ||
if (typeof _this.onPush === 'function' && typeof resp.data.payload != 'undefined') { | ||
@@ -46,2 +48,3 @@ _this.onPush(resp.data.payload); | ||
case interface_1.MessageType.MSG: | ||
/* istanbul ignore else */ | ||
if (resp.data.responseId) { | ||
@@ -80,5 +83,4 @@ var connector = _this.procedures[resp.data.responseId]; | ||
} | ||
AppSDK.fork = function (service, onPush, timeout) { | ||
if (timeout === void 0) { timeout = 10 * 1000; } | ||
var sdk = new AppSDK(onPush, timeout); | ||
AppSDK.fork = function (service, onPush, requestTimeout, connectTimeout) { | ||
var sdk = new AppSDK(onPush, requestTimeout, connectTimeout); | ||
return service(sdk); | ||
@@ -91,6 +93,7 @@ }; | ||
_this.connector.status = window.setTimeout(function () { | ||
_this.connector.status = interface_1.ConnStatus.Failed; | ||
reject(new Error(exception_1.SourceNotFound)); | ||
_this.connector.status = interface_1.ConnStatus.Failed; | ||
}, _this.connectTimeout); | ||
_this.connector.resolve = function () { | ||
/* istanbul ignore else */ | ||
if (_this.connector.status !== interface_1.ConnStatus.Success && | ||
@@ -110,3 +113,5 @@ _this.connector.status != undefined) { | ||
var _this = this; | ||
if (isIsolated === void 0) { isIsolated = false; } | ||
if (!this.connection) { | ||
return Promise.reject(new Error(exception_1.Uninitlized)); | ||
} | ||
if (this.connector.status === interface_1.ConnStatus.Failed) { | ||
@@ -113,0 +118,0 @@ return Promise.reject(new Error(exception_1.SourceNotFound)); |
22527
114
14
20
473