From e5f87c24b880fb6f595b2fd099e85d8029621328 Mon Sep 17 00:00:00 2001 From: wangxiaokou Date: Thu, 22 Feb 2024 19:53:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A1=A5=E5=85=85api-proxy=20ts=E7=94=9F?= =?UTF-8?q?=E5=91=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api-proxy/@types/index.d.ts | 248 +++++++++++++++++++++++ packages/api-proxy/src/platform/index.js | 3 + 2 files changed, 251 insertions(+) diff --git a/packages/api-proxy/@types/index.d.ts b/packages/api-proxy/@types/index.d.ts index b585af4fc9..02068f0479 100644 --- a/packages/api-proxy/@types/index.d.ts +++ b/packages/api-proxy/@types/index.d.ts @@ -32,3 +32,251 @@ declare module '@mpxjs/core' { declare const install: (...args: any) => any export default install + +declare const getProxy: (...args: any) => any + +declare const promisify: (listObj: object, whiteList: string[], customBlackList: string[]) => object + +interface showActionSheetParams { + itemList: string[] +} +declare const showActionSheet: (args: showActionSheetParams) => any + +interface addPhoneContactParams { + firstName: string +} +declare const addPhoneContact: (args: addPhoneContactParams) => any + +declare const onAppShow: (callbackfn: (res: object) => any) => any +declare const onAppHide: (callbackfn: (res: object) => any) => any +declare const offAppShow: (callbackfn: (res: object) => any) => any +declare const offAppHide: (callbackfn: (res: object) => any) => any +interface onErrorParams { + message: string, + stack: string +} +declare const onError: (callbackfn: (res: onErrorParams) => any) => any +declare const offError: (callbackfn: (res: object) => any) => any +declare const createInnerAudioContext: (args: object) => any +declare const base64ToArrayBuffer: (base64: string) => object +declare const arrayBufferToBase64: (arrayBuffer: string[]) => string +interface BLEConnectionParams { + deviceId: string +} +interface BLEStateChangeParams { + deviceId: string, + connected: boolean +} +declare const closeBLEConnection: (args: BLEConnectionParams) => any +declare const createBLEConnection: (args: BLEConnectionParams) => any +declare const onBLEConnectionStateChange: (callbackfn: (res: BLEStateChangeParams) => any) => any +declare const createCanvasContext: (args: object) => any +declare const canvasToTempFilePath: (args: object) => any +interface canvasGetImageDataParams { + canvasId: string, + x: number, + y: number, + width: number, + height: number +} +declare const canvasGetImageData: (args: canvasGetImageDataParams) => any +declare const checkSession: (args: object) => any +interface setClipboardDataParams { + data: string +} +declare const setClipboardData: (args: setClipboardDataParams) => any +declare const getClipboardData: (args: object) => any +declare const createIntersectionObserver: (args: object) => any +declare const createSelectorQuery: () => object +declare const getNetworkType: (args: object) => any +interface onNetworkStatusChangeParams { + isConnected: boolean, + networkType: string +} +declare const onNetworkStatusChange: (callbackfn: (res: onNetworkStatusChangeParams) => any) => any +declare const offNetworkStatusChange: (callbackfn: (res: any) => any) => any +export class EventChannel { + emit(eventName:string, args: any) + off(eventName:string, listener: (args: any) => any) + on(eventName:string, listener: (args: any) => any) + once(eventName:string, listener: (args: any) => any) +} +interface onlyUrlParams { + url: string +} +declare const downloadFile: (args: onlyUrlParams) => any +interface uploadFileParams { + url: string, + filePath: string, + name: string +} +declare const uploadFile: (args: uploadFileParams) => any +declare const getUserInfo: (args: object) => any +interface imageParams { + urls: string[] +} +declare const previewImage: (args: imageParams) => any +declare const compressImage: (args: imageParams) => any +declare const getEnterOptionsSync: () => object +declare const login: (args: object) => any +interface makePhoneCallParams { + phoneNumber: string +} +declare const makePhoneCall: (args: makePhoneCallParams) => any +declare const showModal: (args: object) => any +declare const nextTick: (callbackfn: () => any) => any +declare const pageScrollTo: (args: object) => any +declare const stopPullDownRefresh: (args: object) => any +declare const startPullDownRefresh: (args: object) => any +declare const request: (args: onlyUrlParams) => any +interface requestPaymentParams { + timeStamp: string, + nonceStr: string, + package: string, + paySign: string +} +declare const requestPayment: (args: requestPaymentParams) => any +declare const redirectTo: (args: onlyUrlParams) => any +declare const navigateTo: (args: onlyUrlParams) => any +declare const navigateBack: (args: object) => any +declare const reLaunch: (args: onlyUrlParams) => any +declare const switchTab: (args: onlyUrlParams) => any +declare const scanCode: (args: object) => any +interface screenBrightnessParams { + value: string +} +declare const setScreenBrightness: (args: screenBrightnessParams) => any +declare const getScreenBrightness: (args: object) => any +interface setTitleParams { + title: string +} +declare const setNavigationBarTitle: (args: setTitleParams) => any +interface setNavigationBarColorParams { + frontColor: string, + backgroundColor: string +} +declare const setNavigationBarColor: (args: setNavigationBarColorParams) => any +declare const connectSocket: (args: onlyUrlParams) => any +interface setStorageParams { + key: string, + data: any +} +declare const setStorage: (args: setStorageParams) => any +declare const setStorageSync: (key: string, data: any) => any +interface storageParams { + key: string +} +declare const getStorage: (args: storageParams) => any +declare const removeStorage: (args: storageParams) => any +declare const getStorageSync: (key: string) => any +declare const getStorageInfo: (args: object) => any +declare const getStorageInfoSync: (args: object) => any +declare const removeStorageSync: (key: string) => any +declare const clearStorage: (args: object) => any +declare const clearStorageSync: () => any +declare const getSystemInfo: (args: object) => any +declare const getSystemInfoSync: (args: object) => any +interface setTabBarItemParams { + index: number +} +declare const setTabBarItem: (args: setTabBarItemParams) => any +declare const setTabBarStyle: (args: object) => any +declare const showTabBar: (args: object) => any +declare const hideTabBar: (args: object) => any +interface showToastParams { + title: string +} +declare const showToast: (args: showToastParams) => any +declare const showLoading: (args: showToastParams) => any +declare const hideToast: (args: any) => any +declare const hideLoading: (args: any) => any +declare const createVideoContext: (id: string, context: object) => object +interface windowSize { + windowWidth: number, + windowHeight: number +} +interface onWindowResizeParams { + size: windowSize +} +declare const onWindowResize: (callbackfn: (res: onWindowResizeParams) => any) => any +declare const offWindowResize: (callbackfn: (res: object) => any) => any +declare const createAnimation: (args: any) => any +export { + getProxy, + showActionSheet, + addPhoneContact, + onAppShow, + onAppHide, + offAppHide, + offAppShow, + onError, + offError, + createInnerAudioContext, + base64ToArrayBuffer, + arrayBufferToBase64, + closeBLEConnection, + createBLEConnection, + onBLEConnectionStateChange, + createCanvasContext, + canvasToTempFilePath, + canvasGetImageData, + checkSession, + setClipboardData, + getClipboardData, + createIntersectionObserver, + createSelectorQuery, + getNetworkType, + onNetworkStatusChange, + offNetworkStatusChange, + downloadFile, + uploadFile, + getUserInfo, + previewImage, + compressImage, + getEnterOptionsSync, + login, + makePhoneCall, + showModal, + nextTick, + pageScrollTo, + stopPullDownRefresh, + startPullDownRefresh, + request, + requestPayment, + redirectTo, + navigateTo, + navigateBack, + reLaunch, + switchTab, + setScreenBrightness, + getScreenBrightness, + setNavigationBarTitle, + setNavigationBarColor, + connectSocket, + setStorage, + setStorageSync, + getStorage, + getStorageSync, + getStorageInfo, + getStorageInfoSync, + removeStorage, + removeStorageSync, + clearStorage, + clearStorageSync, + getSystemInfo, + getSystemInfoSync, + setTabBarItem, + setTabBarStyle, + showTabBar, + hideTabBar, + showToast, + hideToast, + showLoading, + hideLoading, + createVideoContext, + onWindowResize, + offWindowResize, + scanCode, + createAnimation, + promisify +} diff --git a/packages/api-proxy/src/platform/index.js b/packages/api-proxy/src/platform/index.js index 390c4f88b1..7c6b462f79 100644 --- a/packages/api-proxy/src/platform/index.js +++ b/packages/api-proxy/src/platform/index.js @@ -107,3 +107,6 @@ export * from './api/window' // getEnterOptionsSync export * from './api/lifecycle' + +// EventChannel +export * from './api/event-channel' From ec2c3561078407ef6f8abaf5aede04c069d0b9b1 Mon Sep 17 00:00:00 2001 From: wangxiaokou Date: Fri, 23 Feb 2024 16:36:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api-proxy/@types/index.d.ts | 329 +++++++-------------------- 1 file changed, 82 insertions(+), 247 deletions(-) diff --git a/packages/api-proxy/@types/index.d.ts b/packages/api-proxy/@types/index.d.ts index 02068f0479..5b1aae93fc 100644 --- a/packages/api-proxy/@types/index.d.ts +++ b/packages/api-proxy/@types/index.d.ts @@ -1,3 +1,5 @@ +/// + type AddPromise = { [K in keyof W]: W[K] extends (...args: any) => any ? Parameters extends [{ success?: (res: infer R) => any }?, ...any[]] @@ -29,254 +31,87 @@ declare module '@mpxjs/core' { } } -declare const install: (...args: any) => any - -export default install - -declare const getProxy: (...args: any) => any +export const getProxy: (...args: any) => void -declare const promisify: (listObj: object, whiteList: string[], customBlackList: string[]) => object +export const promisify: (listObj: object, whiteList: string[], customBlackList: string[]) => object -interface showActionSheetParams { - itemList: string[] -} -declare const showActionSheet: (args: showActionSheetParams) => any +export const showActionSheet: WechatMiniprogram.Wx['showActionSheet'] +export const addPhoneContact: WechatMiniprogram.Wx['addPhoneContact'] +export const onAppShow: WechatMiniprogram.Wx['onAppShow'] +export const onAppHide: WechatMiniprogram.Wx['onAppHide'] +export const offAppShow: WechatMiniprogram.Wx['offAppShow'] +export const offAppHide: WechatMiniprogram.Wx['offAppHide'] +export const onError: WechatMiniprogram.Wx['onError'] +export const offError: WechatMiniprogram.Wx['offError'] +export const createInnerAudioContext: WechatMiniprogram.Wx['createInnerAudioContext'] +export const base64ToArrayBuffer: WechatMiniprogram.Wx['base64ToArrayBuffer'] +export const arrayBufferToBase64: WechatMiniprogram.Wx['arrayBufferToBase64'] +export const closeBLEConnection: WechatMiniprogram.Wx['closeBLEConnection'] +export const createBLEConnection: WechatMiniprogram.Wx['createBLEConnection'] +export const onBLEConnectionStateChange: WechatMiniprogram.Wx['onBLEConnectionStateChange'] +export const createCanvasContext: WechatMiniprogram.Wx['createCanvasContext'] +export const canvasToTempFilePath: WechatMiniprogram.Wx['canvasToTempFilePath'] +export const canvasGetImageData: WechatMiniprogram.Wx['canvasGetImageData'] +export const checkSession: WechatMiniprogram.Wx['checkSession'] +export const setClipboardData: WechatMiniprogram.Wx['setClipboardData'] +export const getClipboardData: WechatMiniprogram.Wx['getClipboardData'] +export const createIntersectionObserver: WechatMiniprogram.Wx['createIntersectionObserver'] +export const createSelectorQuery: WechatMiniprogram.Wx['createSelectorQuery'] +export const getNetworkType: WechatMiniprogram.Wx['getNetworkType'] +export const onNetworkStatusChange: WechatMiniprogram.Wx['onNetworkStatusChange'] +export const offNetworkStatusChange: WechatMiniprogram.Wx['offNetworkStatusChange'] +export const EventChannel: WechatMiniprogram.EventChannel +export const downloadFile: WechatMiniprogram.Wx['downloadFile'] +export const uploadFile: WechatMiniprogram.Wx['uploadFile'] +export const getUserInfo: WechatMiniprogram.Wx['getUserInfo'] +export const previewImage: WechatMiniprogram.Wx['previewImage'] +export const compressImage: WechatMiniprogram.Wx['compressImage'] +export const getEnterOptionsSync: WechatMiniprogram.Wx['getEnterOptionsSync'] +export const login: WechatMiniprogram.Wx['login'] +export const makePhoneCall: WechatMiniprogram.Wx['makePhoneCall'] +export const showModal: WechatMiniprogram.Wx['showModal'] +export const nextTick: WechatMiniprogram.Wx['nextTick'] +export const pageScrollTo: WechatMiniprogram.Wx['pageScrollTo'] +export const stopPullDownRefresh: WechatMiniprogram.Wx['stopPullDownRefresh'] +export const startPullDownRefresh:WechatMiniprogram.Wx['startPullDownRefresh'] +export const request: WechatMiniprogram.Wx['request'] +export const requestPayment: WechatMiniprogram.Wx['requestPayment'] +export const redirectTo: WechatMiniprogram.Wx['redirectTo'] +export const navigateTo: WechatMiniprogram.Wx['navigateTo'] +export const navigateBack: WechatMiniprogram.Wx['navigateBack'] +export const reLaunch: WechatMiniprogram.Wx['reLaunch'] +export const switchTab: WechatMiniprogram.Wx['switchTab'] +export const scanCode: WechatMiniprogram.Wx['scanCode'] +export const setScreenBrightness: WechatMiniprogram.Wx['setScreenBrightness'] +export const getScreenBrightness: WechatMiniprogram.Wx['getScreenBrightness'] +export const setNavigationBarTitle: WechatMiniprogram.Wx['setNavigationBarTitle'] +export const setNavigationBarColor: WechatMiniprogram.Wx['setNavigationBarColor'] +export const connectSocket: WechatMiniprogram.Wx['connectSocket'] +export const setStorage: WechatMiniprogram.Wx['setStorage'] +export const setStorageSync: WechatMiniprogram.Wx['setStorageSync'] +export const getStorage: WechatMiniprogram.Wx['getStorage'] +export const removeStorage: WechatMiniprogram.Wx['removeStorage'] +export const getStorageSync: WechatMiniprogram.Wx['getStorageSync'] +export const getStorageInfo: WechatMiniprogram.Wx['getStorageInfo'] +export const getStorageInfoSync: WechatMiniprogram.Wx['getStorageInfoSync'] +export const removeStorageSync: WechatMiniprogram.Wx['removeStorageSync'] +export const clearStorage: WechatMiniprogram.Wx['clearStorage'] +export const clearStorageSync: WechatMiniprogram.Wx['clearStorageSync'] +export const getSystemInfo: WechatMiniprogram.Wx['getSystemInfo'] +export const getSystemInfoSync: WechatMiniprogram.Wx['getSystemInfoSync'] +export const setTabBarItem: WechatMiniprogram.Wx['setTabBarItem'] +export const setTabBarStyle: WechatMiniprogram.Wx['setTabBarStyle'] +export const showTabBar: WechatMiniprogram.Wx['showTabBar'] +export const hideTabBar: WechatMiniprogram.Wx['hideTabBar'] +export const showToast: WechatMiniprogram.Wx['showToast'] +export const showLoading: WechatMiniprogram.Wx['showLoading'] +export const hideToast: WechatMiniprogram.Wx['hideToast'] +export const hideLoading: WechatMiniprogram.Wx['hideLoading'] +export const createVideoContext: WechatMiniprogram.Wx['createVideoContext'] +export const onWindowResize: WechatMiniprogram.Wx['onWindowResize'] +export const offWindowResize: WechatMiniprogram.Wx['offWindowResize'] +export const createAnimation: WechatMiniprogram.Wx['createAnimation'] -interface addPhoneContactParams { - firstName: string -} -declare const addPhoneContact: (args: addPhoneContactParams) => any +declare const install: (...args: any) => any -declare const onAppShow: (callbackfn: (res: object) => any) => any -declare const onAppHide: (callbackfn: (res: object) => any) => any -declare const offAppShow: (callbackfn: (res: object) => any) => any -declare const offAppHide: (callbackfn: (res: object) => any) => any -interface onErrorParams { - message: string, - stack: string -} -declare const onError: (callbackfn: (res: onErrorParams) => any) => any -declare const offError: (callbackfn: (res: object) => any) => any -declare const createInnerAudioContext: (args: object) => any -declare const base64ToArrayBuffer: (base64: string) => object -declare const arrayBufferToBase64: (arrayBuffer: string[]) => string -interface BLEConnectionParams { - deviceId: string -} -interface BLEStateChangeParams { - deviceId: string, - connected: boolean -} -declare const closeBLEConnection: (args: BLEConnectionParams) => any -declare const createBLEConnection: (args: BLEConnectionParams) => any -declare const onBLEConnectionStateChange: (callbackfn: (res: BLEStateChangeParams) => any) => any -declare const createCanvasContext: (args: object) => any -declare const canvasToTempFilePath: (args: object) => any -interface canvasGetImageDataParams { - canvasId: string, - x: number, - y: number, - width: number, - height: number -} -declare const canvasGetImageData: (args: canvasGetImageDataParams) => any -declare const checkSession: (args: object) => any -interface setClipboardDataParams { - data: string -} -declare const setClipboardData: (args: setClipboardDataParams) => any -declare const getClipboardData: (args: object) => any -declare const createIntersectionObserver: (args: object) => any -declare const createSelectorQuery: () => object -declare const getNetworkType: (args: object) => any -interface onNetworkStatusChangeParams { - isConnected: boolean, - networkType: string -} -declare const onNetworkStatusChange: (callbackfn: (res: onNetworkStatusChangeParams) => any) => any -declare const offNetworkStatusChange: (callbackfn: (res: any) => any) => any -export class EventChannel { - emit(eventName:string, args: any) - off(eventName:string, listener: (args: any) => any) - on(eventName:string, listener: (args: any) => any) - once(eventName:string, listener: (args: any) => any) -} -interface onlyUrlParams { - url: string -} -declare const downloadFile: (args: onlyUrlParams) => any -interface uploadFileParams { - url: string, - filePath: string, - name: string -} -declare const uploadFile: (args: uploadFileParams) => any -declare const getUserInfo: (args: object) => any -interface imageParams { - urls: string[] -} -declare const previewImage: (args: imageParams) => any -declare const compressImage: (args: imageParams) => any -declare const getEnterOptionsSync: () => object -declare const login: (args: object) => any -interface makePhoneCallParams { - phoneNumber: string -} -declare const makePhoneCall: (args: makePhoneCallParams) => any -declare const showModal: (args: object) => any -declare const nextTick: (callbackfn: () => any) => any -declare const pageScrollTo: (args: object) => any -declare const stopPullDownRefresh: (args: object) => any -declare const startPullDownRefresh: (args: object) => any -declare const request: (args: onlyUrlParams) => any -interface requestPaymentParams { - timeStamp: string, - nonceStr: string, - package: string, - paySign: string -} -declare const requestPayment: (args: requestPaymentParams) => any -declare const redirectTo: (args: onlyUrlParams) => any -declare const navigateTo: (args: onlyUrlParams) => any -declare const navigateBack: (args: object) => any -declare const reLaunch: (args: onlyUrlParams) => any -declare const switchTab: (args: onlyUrlParams) => any -declare const scanCode: (args: object) => any -interface screenBrightnessParams { - value: string -} -declare const setScreenBrightness: (args: screenBrightnessParams) => any -declare const getScreenBrightness: (args: object) => any -interface setTitleParams { - title: string -} -declare const setNavigationBarTitle: (args: setTitleParams) => any -interface setNavigationBarColorParams { - frontColor: string, - backgroundColor: string -} -declare const setNavigationBarColor: (args: setNavigationBarColorParams) => any -declare const connectSocket: (args: onlyUrlParams) => any -interface setStorageParams { - key: string, - data: any -} -declare const setStorage: (args: setStorageParams) => any -declare const setStorageSync: (key: string, data: any) => any -interface storageParams { - key: string -} -declare const getStorage: (args: storageParams) => any -declare const removeStorage: (args: storageParams) => any -declare const getStorageSync: (key: string) => any -declare const getStorageInfo: (args: object) => any -declare const getStorageInfoSync: (args: object) => any -declare const removeStorageSync: (key: string) => any -declare const clearStorage: (args: object) => any -declare const clearStorageSync: () => any -declare const getSystemInfo: (args: object) => any -declare const getSystemInfoSync: (args: object) => any -interface setTabBarItemParams { - index: number -} -declare const setTabBarItem: (args: setTabBarItemParams) => any -declare const setTabBarStyle: (args: object) => any -declare const showTabBar: (args: object) => any -declare const hideTabBar: (args: object) => any -interface showToastParams { - title: string -} -declare const showToast: (args: showToastParams) => any -declare const showLoading: (args: showToastParams) => any -declare const hideToast: (args: any) => any -declare const hideLoading: (args: any) => any -declare const createVideoContext: (id: string, context: object) => object -interface windowSize { - windowWidth: number, - windowHeight: number -} -interface onWindowResizeParams { - size: windowSize -} -declare const onWindowResize: (callbackfn: (res: onWindowResizeParams) => any) => any -declare const offWindowResize: (callbackfn: (res: object) => any) => any -declare const createAnimation: (args: any) => any -export { - getProxy, - showActionSheet, - addPhoneContact, - onAppShow, - onAppHide, - offAppHide, - offAppShow, - onError, - offError, - createInnerAudioContext, - base64ToArrayBuffer, - arrayBufferToBase64, - closeBLEConnection, - createBLEConnection, - onBLEConnectionStateChange, - createCanvasContext, - canvasToTempFilePath, - canvasGetImageData, - checkSession, - setClipboardData, - getClipboardData, - createIntersectionObserver, - createSelectorQuery, - getNetworkType, - onNetworkStatusChange, - offNetworkStatusChange, - downloadFile, - uploadFile, - getUserInfo, - previewImage, - compressImage, - getEnterOptionsSync, - login, - makePhoneCall, - showModal, - nextTick, - pageScrollTo, - stopPullDownRefresh, - startPullDownRefresh, - request, - requestPayment, - redirectTo, - navigateTo, - navigateBack, - reLaunch, - switchTab, - setScreenBrightness, - getScreenBrightness, - setNavigationBarTitle, - setNavigationBarColor, - connectSocket, - setStorage, - setStorageSync, - getStorage, - getStorageSync, - getStorageInfo, - getStorageInfoSync, - removeStorage, - removeStorageSync, - clearStorage, - clearStorageSync, - getSystemInfo, - getSystemInfoSync, - setTabBarItem, - setTabBarStyle, - showTabBar, - hideTabBar, - showToast, - hideToast, - showLoading, - hideLoading, - createVideoContext, - onWindowResize, - offWindowResize, - scanCode, - createAnimation, - promisify -} +export default install