@mpxjs/api-proxy
Advanced tools
Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "@mpxjs/api-proxy", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "convert miniprogram API at each end", | ||
@@ -5,0 +5,0 @@ "module": "src/index.js", |
@@ -28,5 +28,6 @@ # mpx-api-proxy | ||
|---|---|---|---|---|---| | ||
|platform|Object|各平台之间的转换|否|{from:'', to:'' }|使用 mpx 脚手架配置会自动进行转换,无需配置| | ||
|exclude|Array(String)|跨平台时不需要转换的 api|-| | ||
|usePromise|Boolean|是否将 api 转化为 promise 格式使用|否|false|-| | ||
|whiteList|Array|将 api 转化为 promise 格式时的白名单|否|[]|需要 usePromise 设为 true| | ||
|platform|Object|各平台之间的转换|否|{from:'', to:'' }|使用 mpx 脚手架配置会自动进行转换,无需配置| | ||
|whiteList|Array(String)|不需要转化 promise 格式的 api|否|[]|需要 usePromise 设为 true| | ||
@@ -33,0 +34,0 @@ ## Done |
@@ -6,8 +6,11 @@ import { proxyWxToAliApi } from './platform/index' | ||
export default function install (target, options = {}) { | ||
const usePromise = !!options.usePromise | ||
const whiteList = options.whiteList || [] | ||
const platform = options.platform || {} | ||
let from = platform.from | ||
let to = platform.to | ||
const { | ||
platform = {}, // 转换的平台 | ||
exclude = [], // 转换平台时不转换的 Api | ||
usePromise = false, // 是否转为 promise 格式 | ||
whiteList = [] // 不变成 promise 格式的 api | ||
} = options | ||
let { from = '', to = '' } = platform | ||
/* eslint-disable camelcase, no-undef */ | ||
@@ -27,3 +30,3 @@ if (typeof __mpx_src_mode__ !== 'undefined') { | ||
if (from === 'wx' && to === 'ali') { | ||
proxyWxToAliApi(target) | ||
proxyWxToAliApi(target, exclude) | ||
} | ||
@@ -33,4 +36,4 @@ | ||
if (usePromise) { | ||
Object.assign(target, getPromisifyList(whiteList, from, to)) | ||
Object.assign(target, getPromisifyList(whiteList, from, to, exclude)) | ||
} | ||
} |
@@ -57,3 +57,3 @@ import { changeOpts, handleSuccess, getEnvObj, error, warn, noop } from '../utils' | ||
hideToast (options) { | ||
if (options.success || options.fail || options.complete) { | ||
if (options && (options.success || options.fail || options.complete)) { | ||
warn(`${TIPS_NAME}.hideToast 不支持 success/fail/complete 参数`) | ||
@@ -647,4 +647,7 @@ } | ||
*/ | ||
const proxyWxToAliApi = target => { | ||
const proxyWxToAliApi = (target, exclude) => { | ||
Object.keys(wxToAliApi).forEach(api => { | ||
if (~exclude.indexOf(api)) { | ||
return | ||
} | ||
target[api] = wxToAliApi[api] | ||
@@ -651,0 +654,0 @@ }) |
@@ -54,7 +54,9 @@ import { wxToAliApi } from './platform/index' | ||
function promisify (listObj, whiteList) { | ||
function promisify (listObj, whiteList, exclude = []) { | ||
const promisifyList = {} | ||
Object.keys(listObj).forEach(key => { | ||
if (typeof listObj[key] !== 'function') return | ||
if (typeof listObj[key] !== 'function' || ~exclude.indexOf(key)) { | ||
return | ||
} | ||
@@ -89,3 +91,3 @@ promisifyList[key] = function (...args) { | ||
export default function getPromisifyList (whiteList, from, to) { | ||
export default function getPromisifyList (whiteList, from, to, exclude) { | ||
const promisifyObj = promisify(envObj, whiteList) | ||
@@ -95,5 +97,5 @@ let promisifyTrans = {} | ||
if (from === 'wx' && to === 'ali') { | ||
promisifyTrans = promisify(wxToAliApi, whiteList) | ||
promisifyTrans = promisify(wxToAliApi, whiteList, exclude) | ||
} | ||
return Object.assign({}, promisifyObj, promisifyTrans) | ||
} |
import { getEnvObj } from './utils' | ||
export default function proxyAll (traget) { | ||
export default function proxyAll (target) { | ||
let envObj = getEnvObj() | ||
@@ -8,5 +8,7 @@ | ||
if (typeof envObj[key] === 'function') { | ||
traget[key] = envObj[key] | ||
target[key] = function (...args) { | ||
envObj[key].apply(envObj, args) | ||
} | ||
} | ||
}) | ||
} |
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
27831
714
36