@goldfishjs/bridge
Advanced tools
Comparing version 1.1.17 to 1.1.18
@@ -26,3 +26,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
my.call(api, params, (result) => { | ||
@@ -38,9 +38,6 @@ resolve(result); | ||
return new Promise((resolve, reject) => { | ||
if (typeof my[api] === | ||
'function' && | ||
params) { | ||
if (typeof my[api] === 'function' && params) { | ||
my[api](Object.assign(Object.assign({}, params), { success(res) { | ||
resolve(res); | ||
}, | ||
fail() { | ||
}, fail() { | ||
reject(); | ||
@@ -47,0 +44,0 @@ } })); |
{ | ||
"name": "@goldfishjs/bridge", | ||
"version": "1.1.17", | ||
"version": "1.1.18", | ||
"description": "goldfish-bridge", | ||
@@ -21,14 +21,14 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.7.0", | ||
"@babel/plugin-transform-classes": "^7.7.0", | ||
"@babel/plugin-transform-runtime": "^7.6.2", | ||
"@babel/preset-env": "^7.7.1", | ||
"@types/jest": "^24.0.23", | ||
"babel-plugin-import": "^1.12.2", | ||
"gulp": "^4.0.2", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-typescript": "^5.0.1", | ||
"jest": "^24.9.0", | ||
"merge2": "^1.3.0", | ||
"ts-jest": "^23.10.2" | ||
"@babel/core": "7.7.0", | ||
"@babel/plugin-transform-classes": "7.7.0", | ||
"@babel/plugin-transform-runtime": "7.6.2", | ||
"@babel/preset-env": "7.7.1", | ||
"@types/jest": "24.0.23", | ||
"babel-plugin-import": "1.12.2", | ||
"gulp": "4.0.2", | ||
"gulp-babel": "8.0.0", | ||
"gulp-typescript": "5.0.1", | ||
"jest": "24.9.0", | ||
"merge2": "1.3.0", | ||
"ts-jest": "23.10.2" | ||
}, | ||
@@ -35,0 +35,0 @@ "types": "./types/index.d.ts", |
// my.xxx type bridge | ||
export type BridgeMethods = Omit< | ||
typeof my, | ||
| 'call' | ||
| 'ap' | ||
| 'reportCustomError' | ||
| 'reportAnalytics' | ||
| 'getRunScene' | ||
| 'SDKVersion' | ||
'call' | 'ap' | 'reportCustomError' | 'reportAnalytics' | 'getRunScene' | 'SDKVersion' | ||
>; | ||
@@ -32,12 +27,8 @@ | ||
// my.xxx | ||
call: async function call< | ||
T extends keyof R, | ||
R extends Record<string, any> = BridgeMethods & SpecialMethods, | ||
>( | ||
api: T, | ||
params?: Parameters<R[T]>[0], | ||
call: async function call<T extends keyof R, R extends Record<string, any> = BridgeMethods & SpecialMethods>( | ||
api: T, | ||
params?: Parameters<R[T]>[0], | ||
): Promise<PickSuccessResult<Parameters<R[T]>[0]>> { | ||
return new Promise((resolve, reject) => { | ||
if ( | ||
typeof (my as R extends BridgeMethods ? R : any)[api] === 'function') { | ||
if (typeof (my as R extends BridgeMethods ? R : any)[api] === 'function') { | ||
(my as R extends BridgeMethods ? R : any)[api]({ | ||
@@ -57,7 +48,5 @@ ...(params as any), | ||
api: string, | ||
params?: P extends Record<string, any> | ||
? P | ||
: Record<string, any> | ((...args: any[]) => void), | ||
params?: P extends Record<string, any> ? P : Record<string, any> | ((...args: any[]) => void), | ||
): Promise<R> { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
my.call(api, params, (result: R) => { | ||
@@ -70,6 +59,3 @@ resolve(result); | ||
// my.ap.xxx | ||
ap: async function ap< | ||
T extends keyof R, | ||
R extends Record<string, Fn> = APBridgeMethods | ||
>( | ||
ap: async function ap<T extends keyof R, R extends Record<string, Fn> = APBridgeMethods>( | ||
api: T, | ||
@@ -79,7 +65,3 @@ params?: Parameters<R[T]>[0], | ||
return new Promise((resolve, reject) => { | ||
if ( | ||
typeof (my as R extends APBridgeMethods ? R : any)[api] === | ||
'function' && | ||
params | ||
) { | ||
if (typeof (my as R extends APBridgeMethods ? R : any)[api] === 'function' && params) { | ||
(my as R extends APBridgeMethods ? R : any)[api]({ | ||
@@ -86,0 +68,0 @@ ...params, |
@@ -1,8 +0,2 @@ | ||
import { | ||
BridgeMethods, | ||
SpecialMethods, | ||
APBridgeMethods, | ||
PickSuccessResult, | ||
Fn, | ||
} from './bridge'; | ||
import { BridgeMethods, SpecialMethods, APBridgeMethods, PickSuccessResult, Fn } from './bridge'; | ||
@@ -27,6 +21,3 @@ function mockServer<T>(host: string, api: string, params?: any): Promise<T> { | ||
// my.xxx | ||
call: async function call< | ||
T extends keyof R, | ||
R extends Record<string, any> = BridgeMethods & SpecialMethods | ||
>( | ||
call: async function call<T extends keyof R, R extends Record<string, any> = BridgeMethods & SpecialMethods>( | ||
host: string, | ||
@@ -43,5 +34,3 @@ api: T, | ||
api: string, | ||
params?: P extends Record<string, any> | ||
? P | ||
: Record<string, any> | ((...args: any[]) => void), | ||
params?: P extends Record<string, any> ? P : Record<string, any> | ((...args: any[]) => void), | ||
): Promise<R> { | ||
@@ -52,6 +41,3 @@ return mockServer<R>(host, api as string, params); | ||
// my.ap.xxx | ||
ap: async function ap< | ||
T extends keyof R, | ||
R extends Record<string, Fn> = APBridgeMethods | ||
>( | ||
ap: async function ap<T extends keyof R, R extends Record<string, Fn> = APBridgeMethods>( | ||
host: string, | ||
@@ -58,0 +44,0 @@ api: T, |
18221
291