miniprogram-api-typings
Advanced tools
Comparing version 2.7.7 to 2.8.0-1
{ | ||
"name": "miniprogram-api-typings", | ||
"version": "2.7.7", | ||
"version": "2.8.0-1", | ||
"description": "Type definitions for APIs of Wechat Mini Program in TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "./index.d.ts", |
@@ -6,3 +6,3 @@ # Wechat Mini Program API Typings | ||
[![](https://img.shields.io/npm/v/miniprogram-api-typings.svg?style=flat)](https://www.npmjs.com/package/miniprogram-api-typings) | ||
[![](https://img.shields.io/github/license/wechat-miniprogram/miniprogram-api-typings.svg)](https://github.com/wechat-miniprogram/miniprogram-api-typings) | ||
[![](https://img.shields.io/github/license/wechat-miniprogram/api-typings.svg)](https://github.com/wechat-miniprogram/api-typings) | ||
@@ -30,3 +30,4 @@ Type definitions for APIs of Wechat Mini Program in TypeScript | ||
-|-|- | ||
[v2.7.7](https://developers.weixin.qq.com/miniprogram/dev/framework/release/) | [2.7.7](https://www.npmjs.com/package/miniprogram-api-typings/v/2.7.7) | `npm install miniprogram-api-typings@2.7.7` | ||
[v2.8.0](https://developers.weixin.qq.com/miniprogram/dev/framework/release/#v2-8-0-2019-07-30) | [2.8.0-1](https://www.npmjs.com/package/miniprogram-api-typings/v/2.8.0-1) | `npm install miniprogram-api-typings@2.8.0-1` | ||
[v2.7.7](https://developers.weixin.qq.com/miniprogram/dev/framework/release/) | [2.7.7-2](https://www.npmjs.com/package/miniprogram-api-typings/v/2.7.7-2) | `npm install miniprogram-api-typings@2.7.7-2` | ||
[v2.6.5](https://developers.weixin.qq.com/miniprogram/dev/framework/release/#v2-6-5-2019-04-02) | [2.6.5-2](https://www.npmjs.com/package/miniprogram-api-typings/v/2.6.5-2) | `npm install miniprogram-api-typings@2.6.5-2` | ||
@@ -33,0 +34,0 @@ [v2.4.2](https://developers.weixin.qq.com/miniprogram/dev/framework/release/v2.html#v2-4-2-2018-12-04)|[2.4.2-2](https://www.npmjs.com/package/miniprogram-api-typings/v/2.4.2-2)|`npm install miniprogram-api-typings@2.4.2-2` |
@@ -28,3 +28,4 @@ # 微信小程序定义文件 | ||
-|-|- | ||
[v2.7.7](https://developers.weixin.qq.com/miniprogram/dev/framework/release/) | [2.7.7](https://www.npmjs.com/package/miniprogram-api-typings/v/2.7.7) | `npm install miniprogram-api-typings@2.7.7` | ||
[v2.8.0](https://developers.weixin.qq.com/miniprogram/dev/framework/release/#v2-8-0-2019-07-30) | [2.8.0-1](https://www.npmjs.com/package/miniprogram-api-typings/v/2.8.0-1) | `npm install miniprogram-api-typings@2.8.0-1` | ||
[v2.7.7](https://developers.weixin.qq.com/miniprogram/dev/framework/release/) | [2.7.7-2](https://www.npmjs.com/package/miniprogram-api-typings/v/2.7.7-2) | `npm install miniprogram-api-typings@2.7.7-2` | ||
[v2.6.5](https://developers.weixin.qq.com/miniprogram/dev/framework/release/#v2-6-5-2019-04-02) | [2.6.5-2](https://www.npmjs.com/package/miniprogram-api-typings/v/2.6.5-2) | `npm install miniprogram-api-typings@2.6.5-2` | ||
@@ -31,0 +32,0 @@ [v2.4.2](https://developers.weixin.qq.com/miniprogram/dev/framework/release/v2.html#v2-4-2-2018-12-04)|[2.4.2-2](https://www.npmjs.com/package/miniprogram-api-typings/v/2.4.2-2)|`npm install miniprogram-api-typings@2.4.2-2` |
/*! ***************************************************************************** | ||
Copyright (c) 2018 Tencent, Inc. All rights reserved. | ||
Copyright (c) 2019 Tencent, Inc. All rights reserved. | ||
@@ -16,9 +16,8 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
/// <reference path="./lib.wx.component.d.ts" /> | ||
/// <reference path="./lib.wx.behavior.d.ts" /> | ||
declare type IAnyObject = Record<string, any>; | ||
declare type KVInfer<T> = { [K in keyof T]: T[K] }; | ||
declare type Void<T> = T | undefined | null; | ||
type PartialOptional<T, K extends keyof T> = Partial<Pick<T, K>> & | ||
Pick<T, Exclude<keyof T, K>>; | ||
declare namespace WechatMiniprogram { | ||
type IAnyObject = Record<string, any> | ||
type Optional<F> = F extends (arg: infer P) => infer R ? (arg?: P) => R : F | ||
type OptionalInterface<T> = { [K in keyof T]: Optional<T[K]> } | ||
} |
/*! ***************************************************************************** | ||
Copyright (c) 2018 Tencent, Inc. All rights reserved. | ||
Copyright (c) 2019 Tencent, Inc. All rights reserved. | ||
@@ -11,239 +11,240 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
declare namespace App { | ||
interface ILaunchOptions { | ||
query: number; | ||
} | ||
declare namespace WechatMiniprogram { | ||
namespace App { | ||
interface ReferrerInfo { | ||
/** 来源小程序或公众号或App的 appId | ||
* | ||
* 以下场景支持返回 referrerInfo.appId: | ||
* - 1020(公众号 profile 页相关小程序列表): appId | ||
* - 1035(公众号自定义菜单):来源公众号 appId | ||
* - 1036(App 分享消息卡片):来源应用 appId | ||
* - 1037(小程序打开小程序):来源小程序 appId | ||
* - 1038(从另一个小程序返回):来源小程序 appId | ||
* - 1043(公众号模板消息):来源公众号 appId | ||
*/ | ||
appId: string | ||
/** 来源小程序传过来的数据,scene=1037或1038时支持 */ | ||
extraData?: any | ||
} | ||
interface IReferrerInfo { | ||
/** 来源小程序或公众号或App的 appId | ||
* | ||
* 以下场景支持返回 referrerInfo.appId: | ||
* - 1020(公众号 profile 页相关小程序列表): appId | ||
* - 1035(公众号自定义菜单):来源公众号 appId | ||
* - 1036(App 分享消息卡片):来源应用 appId | ||
* - 1037(小程序打开小程序):来源小程序 appId | ||
* - 1038(从另一个小程序返回):来源小程序 appId | ||
* - 1043(公众号模板消息):来源公众号 appId | ||
*/ | ||
appId: string; | ||
/** 来源小程序传过来的数据,scene=1037或1038时支持 */ | ||
extraData?: any; | ||
} | ||
type SceneValues = | ||
| 1001 | ||
| 1005 | ||
| 1006 | ||
| 1007 | ||
| 1008 | ||
| 1011 | ||
| 1012 | ||
| 1013 | ||
| 1014 | ||
| 1017 | ||
| 1019 | ||
| 1020 | ||
| 1023 | ||
| 1024 | ||
| 1025 | ||
| 1026 | ||
| 1027 | ||
| 1028 | ||
| 1029 | ||
| 1030 | ||
| 1031 | ||
| 1032 | ||
| 1034 | ||
| 1035 | ||
| 1036 | ||
| 1037 | ||
| 1038 | ||
| 1039 | ||
| 1042 | ||
| 1043 | ||
| 1044 | ||
| 1045 | ||
| 1046 | ||
| 1047 | ||
| 1048 | ||
| 1049 | ||
| 1052 | ||
| 1053 | ||
| 1056 | ||
| 1057 | ||
| 1058 | ||
| 1059 | ||
| 1064 | ||
| 1067 | ||
| 1069 | ||
| 1071 | ||
| 1072 | ||
| 1073 | ||
| 1074 | ||
| 1077 | ||
| 1078 | ||
| 1079 | ||
| 1081 | ||
| 1082 | ||
| 1084 | ||
| 1089 | ||
| 1090 | ||
| 1091 | ||
| 1092 | ||
| 1095 | ||
| 1096 | ||
| 1097 | ||
| 1099 | ||
| 1102 | ||
| 1124 | ||
| 1125 | ||
| 1126 | ||
| 1129 | ||
type SceneValues = | ||
| 1001 | ||
| 1005 | ||
| 1006 | ||
| 1007 | ||
| 1008 | ||
| 1011 | ||
| 1012 | ||
| 1013 | ||
| 1014 | ||
| 1017 | ||
| 1019 | ||
| 1020 | ||
| 1022 | ||
| 1023 | ||
| 1024 | ||
| 1025 | ||
| 1026 | ||
| 1027 | ||
| 1028 | ||
| 1029 | ||
| 1030 | ||
| 1031 | ||
| 1032 | ||
| 1034 | ||
| 1035 | ||
| 1036 | ||
| 1037 | ||
| 1038 | ||
| 1039 | ||
| 1042 | ||
| 1043 | ||
| 1044 | ||
| 1045 | ||
| 1046 | ||
| 1047 | ||
| 1048 | ||
| 1049 | ||
| 1052 | ||
| 1053 | ||
| 1054 | ||
| 1056 | ||
| 1057 | ||
| 1058 | ||
| 1059 | ||
| 1064 | ||
| 1067 | ||
| 1068 | ||
| 1069 | ||
| 1071 | ||
| 1072 | ||
| 1073 | ||
| 1074 | ||
| 1077 | ||
| 1078 | ||
| 1079 | ||
| 1081 | ||
| 1082 | ||
| 1084 | ||
| 1089 | ||
| 1090 | ||
| 1091 | ||
| 1092 | ||
| 1095 | ||
| 1096 | ||
| 1097 | ||
| 1099 | ||
| 1102 | ||
| 1103 | ||
| 1104 | ||
| number; | ||
interface LaunchShowOption { | ||
/** 打开小程序的路径 */ | ||
path: string | ||
/** 打开小程序的query */ | ||
query: IAnyObject | ||
/** 打开小程序的场景值 | ||
* - 1001:发现栏小程序主入口,「最近使用」列表(基础库2.2.4版本起包含「我的小程序」列表) | ||
* - 1005:微信首页顶部搜索框的搜索结果页 | ||
* - 1006:发现栏小程序主入口搜索框的搜索结果页 | ||
* - 1007:单人聊天会话中的小程序消息卡片 | ||
* - 1008:群聊会话中的小程序消息卡片 | ||
* - 1011:扫描二维码 | ||
* - 1012:长按图片识别二维码 | ||
* - 1013:扫描手机相册中选取的二维码 | ||
* - 1014:小程序模板消息 | ||
* - 1017:前往小程序体验版的入口页 | ||
* - 1019:微信钱包(微信客户端7.0.0版本改为支付入口) | ||
* - 1020:公众号 profile 页相关小程序列表 | ||
* - 1023:安卓系统桌面图标 | ||
* - 1024:小程序 profile 页 | ||
* - 1025:扫描一维码 | ||
* - 1026:发现栏小程序主入口,「附近的小程序」列表 | ||
* - 1027:微信首页顶部搜索框搜索结果页「使用过的小程序」列表 | ||
* - 1028:我的卡包 | ||
* - 1029:小程序中的卡券详情页 | ||
* - 1030:自动化测试下打开小程序 | ||
* - 1031:长按图片识别一维码 | ||
* - 1032:扫描手机相册中选取的一维码 | ||
* - 1034:微信支付完成页 | ||
* - 1035:公众号自定义菜单 | ||
* - 1036:App 分享消息卡片 | ||
* - 1037:小程序打开小程序 | ||
* - 1038:从另一个小程序返回 | ||
* - 1039:摇电视 | ||
* - 1042:添加好友搜索框的搜索结果页 | ||
* - 1043:公众号模板消息 | ||
* - 1044:带 shareTicket 的小程序消息卡片 [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html) | ||
* - 1045:朋友圈广告 | ||
* - 1046:朋友圈广告详情页 | ||
* - 1047:扫描小程序码 | ||
* - 1048:长按图片识别小程序码 | ||
* - 1049:扫描手机相册中选取的小程序码 | ||
* - 1052:卡券的适用门店列表 | ||
* - 1053:搜一搜的结果页 | ||
* - 1056:聊天顶部音乐播放器右上角菜单 | ||
* - 1057:钱包中的银行卡详情页 | ||
* - 1058:公众号文章 | ||
* - 1059:体验版小程序绑定邀请页 | ||
* - 1064:微信首页连Wi-Fi状态栏 | ||
* - 1067:公众号文章广告 | ||
* - 1069:移动应用 | ||
* - 1071:钱包中的银行卡列表页 | ||
* - 1072:二维码收款页面 | ||
* - 1073:客服消息列表下发的小程序消息卡片 | ||
* - 1074:公众号会话下发的小程序消息卡片 | ||
* - 1077:摇周边 | ||
* - 1078:微信连Wi-Fi成功提示页 | ||
* - 1079:微信游戏中心 | ||
* - 1081:客服消息下发的文字链 | ||
* - 1082:公众号会话下发的文字链 | ||
* - 1084:朋友圈广告原生页 | ||
* - 1089:微信聊天主界面下拉,「最近使用」栏(基础库2.2.4版本起包含「我的小程序」栏) | ||
* - 1090:长按小程序右上角菜单唤出最近使用历史 | ||
* - 1091:公众号文章商品卡片 | ||
* - 1092:城市服务入口 | ||
* - 1095:小程序广告组件 | ||
* - 1096:聊天记录 | ||
* - 1097:微信支付签约页 | ||
* - 1099:页面内嵌插件 | ||
* - 1102:公众号 profile 页服务预览 | ||
* - 1124:扫“一物一码”打开小程序 | ||
* - 1125:长按图片识别“一物一码” | ||
* - 1126:扫描手机相册中选取的“一物一码” | ||
* - 1129:微信爬虫访问 [详情](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/sitemap.html) | ||
*/ | ||
scene: SceneValues | ||
/** shareTicket,详见 [获取更多转发信息]((转发#获取更多转发信息)) */ | ||
shareTicket: string | ||
/** 当场景为由从另一个小程序或公众号或App打开时,返回此字段 */ | ||
referrerInfo?: ReferrerInfo | ||
} | ||
interface ILaunchShowOption { | ||
/** 打开小程序的路径 */ | ||
path: string; | ||
/** 打开小程序的query */ | ||
query: IAnyObject; | ||
/** 打开小程序的场景值 | ||
* - 1001: 发现栏小程序主入口,「最近使用」列表(基础库2.2.4版本起包含「我的小程序」列表) | ||
* - 1005: 顶部搜索框的搜索结果页 | ||
* - 1006: 发现栏小程序主入口搜索框的搜索结果页 | ||
* - 1007: 单人聊天会话中的小程序消息卡片 | ||
* - 1008: 群聊会话中的小程序消息卡片 | ||
* - 1011: 扫描二维码 | ||
* - 1012: 长按图片识别二维码 | ||
* - 1013: 手机相册选取二维码 | ||
* - 1014: 小程序模板消息 | ||
* - 1017: 前往体验版的入口页 | ||
* - 1019: 微信钱包 | ||
* - 1020: 公众号 profile 页相关小程序列表 | ||
* - 1022: 聊天顶部置顶小程序入口 | ||
* - 1023: 安卓系统桌面图标 | ||
* - 1024: 小程序 profile 页 | ||
* - 1025: 扫描一维码 | ||
* - 1026: 附近小程序列表 | ||
* - 1027: 顶部搜索框搜索结果页「使用过的小程序」列表 | ||
* - 1028: 我的卡包 | ||
* - 1029: 卡券详情页 | ||
* - 1030: 自动化测试下打开小程序 | ||
* - 1031: 长按图片识别一维码 | ||
* - 1032: 手机相册选取一维码 | ||
* - 1034: 微信支付完成页 | ||
* - 1035: 公众号自定义菜单 | ||
* - 1036: App 分享消息卡片 | ||
* - 1037: 小程序打开小程序 | ||
* - 1038: 从另一个小程序返回 | ||
* - 1039: 摇电视 | ||
* - 1042: 添加好友搜索框的搜索结果页 | ||
* - 1043: 公众号模板消息 | ||
* - 1044: 带 shareTicket 的小程序消息卡片 [详情]((转发#获取更多转发信息)) | ||
* - 1045: 朋友圈广告 | ||
* - 1046: 朋友圈广告详情页 | ||
* - 1047: 扫描小程序码 | ||
* - 1048: 长按图片识别小程序码 | ||
* - 1049: 手机相册选取小程序码 | ||
* - 1052: 卡券的适用门店列表 | ||
* - 1053: 搜一搜的结果页 | ||
* - 1054: 顶部搜索框小程序快捷入口 | ||
* - 1056: 音乐播放器菜单 | ||
* - 1057: 钱包中的银行卡详情页 | ||
* - 1058: 公众号文章 | ||
* - 1059: 体验版小程序绑定邀请页 | ||
* - 1064: 微信连Wi-Fi状态栏 | ||
* - 1067: 公众号文章广告 | ||
* - 1068: 附近小程序列表广告 | ||
* - 1069: 移动应用 | ||
* - 1071: 钱包中的银行卡列表页 | ||
* - 1072: 二维码收款页面 | ||
* - 1073: 客服消息列表下发的小程序消息卡片 | ||
* - 1074: 公众号会话下发的小程序消息卡片 | ||
* - 1077: 摇周边 | ||
* - 1078: 连Wi-Fi成功页 | ||
* - 1079: 微信游戏中心 | ||
* - 1081: 客服消息下发的文字链 | ||
* - 1082: 公众号会话下发的文字链 | ||
* - 1084: 朋友圈广告原生页 | ||
* - 1089: 微信聊天主界面下拉,「最近使用」栏(基础库2.2.4版本起包含「我的小程序」栏) | ||
* - 1090: 长按小程序右上角菜单唤出最近使用历史 | ||
* - 1091: 公众号文章商品卡片 | ||
* - 1092: 城市服务入口 | ||
* - 1095: 小程序广告组件 | ||
* - 1096: 聊天记录 | ||
* - 1097: 微信支付签约页 | ||
* - 1099: 页面内嵌插件 | ||
* - 1102: 公众号 profile 页服务预览 | ||
* - 1103: 发现栏小程序主入口,「我的小程序」列表(基础库2.2.4版本起废弃) | ||
* - 1104: 微信聊天主界面下拉,「我的小程序」栏(基础库2.2.4版本起废弃) | ||
*/ | ||
scene: SceneValues; | ||
/** shareTicket,详见 [获取更多转发信息]((转发#获取更多转发信息)) */ | ||
shareTicket: string; | ||
/** 当场景为由从另一个小程序或公众号或App打开时,返回此字段 */ | ||
referrerInfo?: IReferrerInfo; | ||
} | ||
interface PageNotFoundOption { | ||
/** 不存在页面的路径 */ | ||
path: string | ||
/** 打开不存在页面的 query */ | ||
query: IAnyObject | ||
/** 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */ | ||
isEntryPage: boolean | ||
} | ||
interface IPageNotFoundOption { | ||
/** 不存在页面的路径 */ | ||
path: string; | ||
/** 打开不存在页面的 query */ | ||
query: IAnyObject; | ||
/** 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */ | ||
isEntryPage: boolean; | ||
} | ||
interface Option { | ||
/** 生命周期回调—监听小程序初始化 | ||
* | ||
* 小程序初始化完成时触发,全局只触发一次。 | ||
*/ | ||
onLaunch(options: LaunchShowOption): void | ||
/** 生命周期回调—监听小程序显示 | ||
* | ||
* 小程序启动,或从后台进入前台显示时 | ||
*/ | ||
onShow(options: LaunchShowOption): void | ||
/** 生命周期回调—监听小程序隐藏 | ||
* | ||
* 小程序从前台进入后台时 | ||
*/ | ||
onHide(): void | ||
/** 错误监听函数 | ||
* | ||
* 小程序发生脚本错误,或者 api | ||
*/ | ||
onError(/** 错误信息,包含堆栈 */ error: string): void | ||
/** 页面不存在监听函数 | ||
* | ||
* 小程序要打开的页面不存在时触发,会带上页面信息回调该函数 | ||
* | ||
* **注意:** | ||
* 1. 如果开发者没有添加 `onPageNotFound` 监听,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。 | ||
* 2. 如果 `onPageNotFound` 回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再回调 `onPageNotFound`。 | ||
* | ||
* 最低基础库: 1.9.90 | ||
*/ | ||
onPageNotFound(options: PageNotFoundOption): void | ||
} | ||
interface AppInstance<T extends IAnyObject = {}> { | ||
/** 生命周期回调—监听小程序初始化 | ||
* | ||
* 小程序初始化完成时触发,全局只触发一次。 | ||
*/ | ||
onLaunch?(options?: ILaunchShowOption): void; | ||
/** 生命周期回调—监听小程序显示 | ||
* | ||
* 小程序启动,或从后台进入前台显示时 | ||
*/ | ||
onShow?(options?: ILaunchShowOption): void; | ||
/** 生命周期回调—监听小程序隐藏 | ||
* | ||
* 小程序从前台进入后台时 | ||
*/ | ||
onHide?(): void; | ||
/** 错误监听函数 | ||
* | ||
* 小程序发生脚本错误,或者 api | ||
*/ | ||
onError?(/** 错误信息,包含堆栈 */ error?: string): void; | ||
/** 页面不存在监听函数 | ||
* | ||
* 小程序要打开的页面不存在时触发,会带上页面信息回调该函数 | ||
* | ||
* **注意:** | ||
* 1. 如果开发者没有添加 `onPageNotFound` 监听,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。 | ||
* 2. 如果 `onPageNotFound` 回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再回调 `onPageNotFound`。 | ||
* | ||
* 最低基础库: 1.9.90 | ||
*/ | ||
onPageNotFound?(options?: IPageNotFoundOption): void; | ||
} | ||
type Instance<T extends IAnyObject> = Option & T | ||
type Options<T extends IAnyObject> = Partial<Option> & | ||
T & | ||
ThisType<Instance<T>> | ||
type TrivialInstance = Instance<IAnyObject> | ||
interface AppConstructor { | ||
<T extends IAnyObject & AppInstance>(options: AppInstance<T> & T): void; | ||
} | ||
interface Constructor { | ||
<T extends IAnyObject>(options: Options<T>): void | ||
} | ||
interface IGetAppOption { | ||
/** 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包 | ||
* | ||
* 最低基础库: 2.2.4 | ||
*/ | ||
allowDefault: boolean; | ||
} | ||
interface GetAppOption { | ||
/** 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包 | ||
* | ||
* 最低基础库: 2.2.4 | ||
*/ | ||
allowDefault?: boolean | ||
} | ||
interface GetApp { | ||
<T extends IAnyObject>(opts?: IGetAppOption): AppInstance<T> & T; | ||
} | ||
interface GetApp { | ||
(opts?: GetAppOption): TrivialInstance | ||
} | ||
} | ||
} | ||
declare const App: App.AppConstructor; | ||
declare const getApp: App.GetApp; | ||
declare const App: WechatMiniprogram.App.Constructor | ||
declare const getApp: WechatMiniprogram.App.GetApp |
/*! ***************************************************************************** | ||
Copyright (c) 2018 Tencent, Inc. All rights reserved. | ||
Copyright (c) 2019 Tencent, Inc. All rights reserved. | ||
@@ -20,53 +20,53 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
interface IAPIError { | ||
errMsg: string; | ||
errMsg: string | ||
} | ||
interface IAPIParam<T = any> { | ||
config?: ICloudConfig; | ||
success?: (res: T) => void; | ||
fail?: (err: IAPIError) => void; | ||
complete?: (val: T | IAPIError) => void; | ||
config?: ICloudConfig | ||
success?: (res: T) => void | ||
fail?: (err: IAPIError) => void | ||
complete?: (val: T | IAPIError) => void | ||
} | ||
interface IAPISuccessParam { | ||
errMsg: string; | ||
errMsg: string | ||
} | ||
type IAPICompleteParam = IAPISuccessParam | IAPIError; | ||
type IAPICompleteParam = IAPISuccessParam | IAPIError | ||
type IAPIFunction<T, P extends IAPIParam<T>> = (param?: P) => Promise<T> | any; | ||
type IAPIFunction<T, P extends IAPIParam<T>> = (param?: P) => Promise<T> | ||
interface IInitCloudConfig { | ||
env?: | ||
| string | ||
| { | ||
database?: string; | ||
functions?: string; | ||
storage?: string; | ||
}; | ||
traceUser?: boolean; | ||
env?: | ||
| string | ||
| { | ||
database?: string | ||
functions?: string | ||
storage?: string, | ||
} | ||
traceUser?: boolean | ||
} | ||
interface ICloudConfig { | ||
env?: string; | ||
traceUser?: boolean; | ||
env?: string | ||
traceUser?: boolean | ||
} | ||
interface IICloudAPI { | ||
init: (config?: IInitCloudConfig) => void; | ||
[api: string]: AnyFunction | IAPIFunction<any, any>; | ||
init: (config?: IInitCloudConfig) => void | ||
[api: string]: AnyFunction | IAPIFunction<any, any> | ||
} | ||
interface ICloudService { | ||
name: string; | ||
name: string | ||
getAPIs: () => { [name: string]: IAPIFunction<any, any> }; | ||
getAPIs: () => { [name: string]: IAPIFunction<any, any> } | ||
} | ||
interface ICloudServices { | ||
[serviceName: string]: ICloudService; | ||
[serviceName: string]: ICloudService | ||
} | ||
interface ICloudMetaData { | ||
session_id: string; | ||
session_id: string | ||
} | ||
@@ -76,250 +76,123 @@ | ||
type AnyObject = { | ||
[x: string]: any; | ||
}; | ||
interface AnyObject { | ||
[x: string]: any | ||
} | ||
type AnyArray = any[]; | ||
type AnyArray = any[] | ||
type AnyFunction = (...args: any[]) => any; | ||
type AnyFunction = (...args: any[]) => any | ||
/** | ||
* original wx | ||
*/ | ||
declare namespace WXNS { | ||
interface AnyObject { | ||
[key: string]: any; | ||
} | ||
interface IAPIParam<T> { | ||
success?: (res: T) => void; | ||
fail?: (err: IAPIError) => void; | ||
complete?: (val: T | IAPIError) => void; | ||
} | ||
interface CommonAPIResult { | ||
errMsg: string; | ||
} | ||
interface IAPIError { | ||
errMsg: string; | ||
} | ||
interface IProgressUpdateEvent { | ||
progress: number; | ||
totalBytesWritten: number; | ||
totalBytesExpectedToWrite: number; | ||
} | ||
interface operateWXData { | ||
(param: any): void; | ||
} | ||
interface uploadFile { | ||
/** | ||
* upload file | ||
* @param param | ||
*/ | ||
(param: IUploadFileParam): IUploadFileTask; | ||
} | ||
interface IUploadFileParam extends IAPIParam<IUploadFileSuccessResult> { | ||
url: string; | ||
filePath: string; | ||
name: string; | ||
header?: AnyObject; | ||
} | ||
interface IUploadFileSuccessResult extends CommonAPIResult { | ||
data: string; | ||
statusCode: number; | ||
} | ||
interface IUploadFileTask { | ||
onProgressUpdate: (fn: (event: IProgressUpdateEvent) => void) => void; | ||
abort: AnyFunction; | ||
} | ||
interface downloadFile { | ||
/** | ||
* download file | ||
* @param param | ||
*/ | ||
(param: IDownloadFileParam): IDownloadFileTask; | ||
} | ||
interface IDownloadFileParam extends IAPIParam<IDownloadFileSuccessResult> { | ||
url: string; | ||
header?: AnyObject; | ||
} | ||
interface IDownloadFileSuccessResult extends CommonAPIResult { | ||
tempFilePath: string; | ||
statusCode: number; | ||
} | ||
interface IDownloadFileTask { | ||
onProgressUpdate: (fn: (event: IProgressUpdateEvent) => void) => void; | ||
abort: AnyFunction; | ||
} | ||
interface request { | ||
(param: IRequestParam): IRequestTask; | ||
} | ||
interface IRequestParam extends IAPIParam<IRequestSuccessResult> { | ||
url: string; | ||
data?: AnyObject | string | ArrayBuffer; | ||
header?: AnyObject; | ||
method?: string; | ||
dataType?: string; | ||
responseType?: string; | ||
} | ||
interface IRequestSuccessResult { | ||
data: AnyObject | string | ArrayBuffer; | ||
statusCode: number; | ||
header: AnyObject; | ||
} | ||
interface IRequestTask { | ||
abort: () => void; | ||
} | ||
interface getFileInfo { | ||
(param: IGetFileInfoParam): void; | ||
} | ||
interface IGetFileInfoParam extends IAPIParam<IGetFileInfoSuccessResult> { | ||
filePath: string; | ||
digestAlgorithm?: string; | ||
} | ||
interface IGetFileInfoSuccessResult { | ||
size: number; | ||
digest: string; | ||
} | ||
} | ||
/** | ||
* extend wx with cloud | ||
*/ | ||
interface WxCloud { | ||
init: (config?: ICloudConfig) => void; | ||
init: (config?: ICloudConfig) => void | ||
// callFunction: (param: ICloud.CallFunctionParam) => Promise<ICloud.CallFunctionResult> | void, | ||
callFunction(param: OQ<ICloud.CallFunctionParam>): void | ||
callFunction( | ||
param: RQ<ICloud.CallFunctionParam>, | ||
): Promise<ICloud.CallFunctionResult> | ||
// uploadFile: (param: ICloud.UploadFileParam) => Promise<ICloud.UploadFileResult> | WXNS.IUploadFileTask, | ||
// downloadFile: (param: ICloud.DownloadFileParam) => Promise<ICloud.DownloadFileResult> | WXNS.IDownloadFileTask, | ||
// getTempFileURL: (param: ICloud.GetTempFileURLParam) => Promise<ICloud.GetTempFileURLResult> | void, | ||
// deleteFile: (param: ICloud.DeleteFileParam) => Promise<ICloud.DeleteFileResult> | void, | ||
uploadFile(param: OQ<ICloud.UploadFileParam>): WechatMiniprogram.UploadTask | ||
uploadFile( | ||
param: RQ<ICloud.UploadFileParam>, | ||
): Promise<ICloud.UploadFileResult> | ||
callFunction(param: OQ<ICloud.CallFunctionParam>): void; | ||
callFunction( | ||
param: RQ<ICloud.CallFunctionParam>, | ||
): Promise<ICloud.CallFunctionResult>; | ||
downloadFile( | ||
param: OQ<ICloud.DownloadFileParam>, | ||
): WechatMiniprogram.DownloadTask | ||
downloadFile( | ||
param: RQ<ICloud.DownloadFileParam>, | ||
): Promise<ICloud.DownloadFileResult> | ||
uploadFile(param: OQ<ICloud.UploadFileParam>): WXNS.IUploadFileTask; | ||
uploadFile( | ||
param: RQ<ICloud.UploadFileParam>, | ||
): Promise<ICloud.UploadFileResult>; | ||
getTempFileURL(param: OQ<ICloud.GetTempFileURLParam>): void | ||
getTempFileURL( | ||
param: RQ<ICloud.GetTempFileURLParam>, | ||
): Promise<ICloud.GetTempFileURLResult> | ||
downloadFile(param: OQ<ICloud.DownloadFileParam>): WXNS.IDownloadFileTask; | ||
downloadFile( | ||
param: RQ<ICloud.DownloadFileParam>, | ||
): Promise<ICloud.DownloadFileResult>; | ||
deleteFile(param: OQ<ICloud.DeleteFileParam>): void | ||
deleteFile( | ||
param: RQ<ICloud.DeleteFileParam>, | ||
): Promise<ICloud.DeleteFileResult> | ||
getTempFileURL(param: OQ<ICloud.GetTempFileURLParam>): void; | ||
getTempFileURL( | ||
param: RQ<ICloud.GetTempFileURLParam>, | ||
): Promise<ICloud.GetTempFileURLResult>; | ||
deleteFile(param: OQ<ICloud.DeleteFileParam>): void; | ||
deleteFile( | ||
param: RQ<ICloud.DeleteFileParam>, | ||
): Promise<ICloud.DeleteFileResult>; | ||
database: (config?: ICloudConfig) => DB.Database; | ||
database: (config?: ICloudConfig) => DB.Database | ||
} | ||
declare namespace ICloud { | ||
interface ICloudAPIParam<T = any> extends IAPIParam<T> { | ||
config?: ICloudConfig; | ||
} | ||
interface ICloudAPIParam<T = any> extends IAPIParam<T> { | ||
config?: ICloudConfig | ||
} | ||
// === API: callFunction === | ||
export type CallFunctionData = AnyObject; | ||
// === API: callFunction === | ||
type CallFunctionData = AnyObject | ||
export interface CallFunctionResult extends IAPISuccessParam { | ||
result: AnyObject | string | undefined; | ||
} | ||
interface CallFunctionResult extends IAPISuccessParam { | ||
result: AnyObject | string | undefined | ||
} | ||
export interface CallFunctionParam | ||
extends ICloudAPIParam<CallFunctionResult> { | ||
name: string; | ||
data?: CallFunctionData; | ||
slow?: boolean; | ||
} | ||
// === end === | ||
interface CallFunctionParam extends ICloudAPIParam<CallFunctionResult> { | ||
name: string | ||
data?: CallFunctionData | ||
slow?: boolean | ||
} | ||
// === end === | ||
// === API: uploadFile === | ||
export interface UploadFileResult extends IAPISuccessParam { | ||
fileID: string; | ||
statusCode: number; | ||
} | ||
// === API: uploadFile === | ||
interface UploadFileResult extends IAPISuccessParam { | ||
fileID: string | ||
statusCode: number | ||
} | ||
export interface UploadFileParam extends ICloudAPIParam<UploadFileResult> { | ||
cloudPath: string; | ||
filePath: string; | ||
header?: AnyObject; | ||
} | ||
// === end === | ||
interface UploadFileParam extends ICloudAPIParam<UploadFileResult> { | ||
cloudPath: string | ||
filePath: string | ||
header?: AnyObject | ||
} | ||
// === end === | ||
// === API: downloadFile === | ||
export interface DownloadFileResult extends IAPISuccessParam { | ||
tempFilePath: string; | ||
statusCode: number; | ||
} | ||
// === API: downloadFile === | ||
interface DownloadFileResult extends IAPISuccessParam { | ||
tempFilePath: string | ||
statusCode: number | ||
} | ||
export interface DownloadFileParam | ||
extends ICloudAPIParam<DownloadFileResult> { | ||
fileID: string; | ||
cloudPath?: string; | ||
} | ||
// === end === | ||
interface DownloadFileParam extends ICloudAPIParam<DownloadFileResult> { | ||
fileID: string | ||
cloudPath?: string | ||
} | ||
// === end === | ||
// === API: getTempFileURL === | ||
export interface GetTempFileURLResult extends IAPISuccessParam { | ||
fileList: GetTempFileURLResultItem[]; | ||
} | ||
// === API: getTempFileURL === | ||
interface GetTempFileURLResult extends IAPISuccessParam { | ||
fileList: GetTempFileURLResultItem[] | ||
} | ||
export interface GetTempFileURLResultItem { | ||
fileID: string; | ||
tempFileURL: string; | ||
maxAge: number; | ||
status: number; | ||
errMsg: string; | ||
} | ||
interface GetTempFileURLResultItem { | ||
fileID: string | ||
tempFileURL: string | ||
maxAge: number | ||
status: number | ||
errMsg: string | ||
} | ||
export interface GetTempFileURLParam | ||
extends ICloudAPIParam<GetTempFileURLResult> { | ||
fileList: string[]; | ||
} | ||
// === end === | ||
interface GetTempFileURLParam extends ICloudAPIParam<GetTempFileURLResult> { | ||
fileList: string[] | ||
} | ||
// === end === | ||
// === API: deleteFile === | ||
interface DeleteFileResult extends IAPISuccessParam { | ||
fileList: DeleteFileResultItem[]; | ||
} | ||
// === API: deleteFile === | ||
interface DeleteFileResult extends IAPISuccessParam { | ||
fileList: DeleteFileResultItem[] | ||
} | ||
interface DeleteFileResultItem { | ||
fileID: string; | ||
status: number; | ||
errMsg: string; | ||
} | ||
interface DeleteFileResultItem { | ||
fileID: string | ||
status: number | ||
errMsg: string | ||
} | ||
interface DeleteFileParam extends ICloudAPIParam<DeleteFileResult> { | ||
fileList: string[]; | ||
} | ||
// === end === | ||
interface DeleteFileParam extends ICloudAPIParam<DeleteFileResult> { | ||
fileList: string[] | ||
} | ||
// === end === | ||
} | ||
@@ -329,537 +202,511 @@ | ||
declare namespace DB { | ||
/** | ||
* The class of all exposed cloud database instances | ||
*/ | ||
export class Database { | ||
public readonly config: ICloudConfig; | ||
public readonly command: DatabaseCommand; | ||
public readonly Geo: IGeo; | ||
public readonly serverDate: () => ServerDate; | ||
public readonly RegExp: IRegExpConstructor; | ||
/** | ||
* The class of all exposed cloud database instances | ||
*/ | ||
class Database { | ||
readonly config: ICloudConfig | ||
readonly command: DatabaseCommand | ||
readonly Geo: IGeo | ||
readonly serverDate: () => ServerDate | ||
readonly RegExp: IRegExpConstructor | ||
private constructor(); | ||
private constructor() | ||
collection(collectionName: string): CollectionReference; | ||
} | ||
collection(collectionName: string): CollectionReference | ||
} | ||
export class CollectionReference extends Query { | ||
public readonly collectionName: string; | ||
public readonly database: Database; | ||
class CollectionReference extends Query { | ||
readonly collectionName: string | ||
readonly database: Database | ||
private constructor(name: string, database: Database); | ||
private constructor(name: string, database: Database) | ||
doc(docId: string | number): DocumentReference; | ||
doc(docId: string | number): DocumentReference | ||
// add(options: IAddDocumentOptions): Promise<IAddResult> | void | ||
// add(options: IAddDocumentOptions): Promise<IAddResult> | void | ||
add(options: OQ<IAddDocumentOptions>): void; | ||
add(options: RQ<IAddDocumentOptions>): Promise<IAddResult>; | ||
} | ||
add(options: OQ<IAddDocumentOptions>): void | ||
add(options: RQ<IAddDocumentOptions>): Promise<IAddResult> | ||
} | ||
export class DocumentReference { | ||
private constructor(docId: string | number, database: Database); | ||
class DocumentReference { | ||
private constructor(docId: string | number, database: Database) | ||
field(object: object): this; | ||
field(object: object): this | ||
// get(options?: IGetDocumentOptions): Promise<IQuerySingleResult> | void | ||
get(options: OQ<IGetDocumentOptions>): void | ||
get(options?: RQ<IGetDocumentOptions>): Promise<IQuerySingleResult> | ||
// set(options?: ISetSingleDocumentOptions): Promise<ISetResult> | void | ||
set(options: OQ<ISetSingleDocumentOptions>): void | ||
set(options?: RQ<ISetSingleDocumentOptions>): Promise<ISetResult> | ||
// update(options?: IUpdateSingleDocumentOptions): Promise<IUpdateResult> | void | ||
update(options: OQ<IUpdateSingleDocumentOptions>): void | ||
update( | ||
options?: RQ<IUpdateSingleDocumentOptions>, | ||
): Promise<IUpdateResult> | ||
// remove(options?: IRemoveSingleDocumentOptions): Promise<IRemoveResult> | void | ||
remove(options: OQ<IRemoveSingleDocumentOptions>): void | ||
remove( | ||
options?: RQ<IRemoveSingleDocumentOptions>, | ||
): Promise<IRemoveResult> | ||
} | ||
// get(options?: IGetDocumentOptions): Promise<IQuerySingleResult> | void | ||
get(): Promise<IQuerySingleResult>; | ||
get(options: OQ<IGetDocumentOptions>): void; | ||
get(options: RQ<IGetDocumentOptions>): Promise<IQuerySingleResult>; | ||
class Query { | ||
where(condition: IQueryCondition): Query | ||
// set(options?: ISetSingleDocumentOptions): Promise<ISetResult> | void | ||
set(): Promise<ISetResult>; | ||
set(options: OQ<ISetSingleDocumentOptions>): void; | ||
set(options: RQ<ISetSingleDocumentOptions>): Promise<ISetResult>; | ||
orderBy(fieldPath: string, order: string): Query | ||
// update(options?: IUpdateSingleDocumentOptions): Promise<IUpdateResult> | void | ||
update(): Promise<IUpdateResult>; | ||
update(options: OQ<IUpdateSingleDocumentOptions>): void; | ||
update(options: RQ<IUpdateSingleDocumentOptions>): Promise<IUpdateResult>; | ||
limit(max: number): Query | ||
// remove(options?: IRemoveSingleDocumentOptions): Promise<IRemoveResult> | void | ||
remove(): Promise<IRemoveResult>; | ||
remove(options: OQ<IRemoveSingleDocumentOptions>): void; | ||
remove(options: RQ<IRemoveSingleDocumentOptions>): Promise<IRemoveResult>; | ||
} | ||
skip(offset: number): Query | ||
export class Query { | ||
where(condition: IQueryCondition): Query; | ||
field(object: object): Query | ||
orderBy(fieldPath: string, order: string): Query; | ||
get(options: OQ<IGetDocumentOptions>): void | ||
get(options?: RQ<IGetDocumentOptions>): Promise<IQueryResult> | ||
limit(max: number): Query; | ||
count(options: OQ<ICountDocumentOptions>): void | ||
count(options?: RQ<ICountDocumentOptions>): Promise<ICountResult> | ||
} | ||
skip(offset: number): Query; | ||
interface DatabaseCommand { | ||
eq(val: any): DatabaseQueryCommand | ||
neq(val: any): DatabaseQueryCommand | ||
gt(val: any): DatabaseQueryCommand | ||
gte(val: any): DatabaseQueryCommand | ||
lt(val: any): DatabaseQueryCommand | ||
lte(val: any): DatabaseQueryCommand | ||
in(val: any[]): DatabaseQueryCommand | ||
nin(val: any[]): DatabaseQueryCommand | ||
field(object: object): Query; | ||
geoNear(options: IGeoNearCommandOptions): DatabaseQueryCommand | ||
geoWithin(options: IGeoWithinCommandOptions): DatabaseQueryCommand | ||
geoIntersects( | ||
options: IGeoIntersectsCommandOptions, | ||
): DatabaseQueryCommand | ||
// get(options?: IGetDocumentOptions): Promise<IQueryResult> | void | ||
and( | ||
...expressions: Array<DatabaseLogicCommand | IQueryCondition> | ||
): DatabaseLogicCommand | ||
or( | ||
...expressions: Array<DatabaseLogicCommand | IQueryCondition> | ||
): DatabaseLogicCommand | ||
// // update(options?: IUpdateDocumentOptions): Promise<IUpdateResult> | void | ||
set(val: any): DatabaseUpdateCommand | ||
remove(): DatabaseUpdateCommand | ||
inc(val: number): DatabaseUpdateCommand | ||
mul(val: number): DatabaseUpdateCommand | ||
// // remove(options?: IRemoveDocumentOptions): Promise<IRemoveResult> | void | ||
push(...values: any[]): DatabaseUpdateCommand | ||
pop(): DatabaseUpdateCommand | ||
shift(): DatabaseUpdateCommand | ||
unshift(...values: any[]): DatabaseUpdateCommand | ||
} | ||
// count(options?: ICountDocumentOptions): Promise<ICountResult> | void | ||
enum LOGIC_COMMANDS_LITERAL { | ||
AND = 'and', | ||
OR = 'or', | ||
NOT = 'not', | ||
NOR = 'nor', | ||
} | ||
// get(options?: IGetDocumentOptions): Promise<IQueryResult> | void | ||
get(): Promise<IQueryResult>; | ||
get(options: OQ<IGetDocumentOptions>): void; | ||
get(options: RQ<IGetDocumentOptions>): Promise<IQueryResult>; | ||
class DatabaseLogicCommand { | ||
fieldName: string | InternalSymbol | ||
operator: LOGIC_COMMANDS_LITERAL | string | ||
operands: any[] | ||
// update(options?: IUpdateDocumentOptions): Promise<IUpdateResult> | void | ||
_setFieldName(fieldName: string): DatabaseLogicCommand | ||
// remove(options?: IRemoveDocumentOptions): Promise<IRemoveResult> | void | ||
and( | ||
...expressions: Array<DatabaseLogicCommand | IQueryCondition> | ||
): DatabaseLogicCommand | ||
or( | ||
...expressions: Array<DatabaseLogicCommand | IQueryCondition> | ||
): DatabaseLogicCommand | ||
} | ||
// count(options?: ICountDocumentOptions): Promise<ICountResult> | void | ||
count(): Promise<ICountResult>; | ||
count(options: OQ<ICountDocumentOptions>): void; | ||
count(options: RQ<ICountDocumentOptions>): Promise<ICountResult>; | ||
} | ||
enum QUERY_COMMANDS_LITERAL { | ||
// normal | ||
EQ = 'eq', | ||
NEQ = 'neq', | ||
GT = 'gt', | ||
GTE = 'gte', | ||
LT = 'lt', | ||
LTE = 'lte', | ||
IN = 'in', | ||
NIN = 'nin', | ||
// geo | ||
GEO_NEAR = 'geoNear', | ||
GEO_WITHIN = 'geoWithin', | ||
GEO_INTERSECTS = 'geoIntersects', | ||
} | ||
export interface DatabaseCommand { | ||
eq(val: any): DatabaseQueryCommand; | ||
neq(val: any): DatabaseQueryCommand; | ||
gt(val: any): DatabaseQueryCommand; | ||
gte(val: any): DatabaseQueryCommand; | ||
lt(val: any): DatabaseQueryCommand; | ||
lte(val: any): DatabaseQueryCommand; | ||
in(val: any[]): DatabaseQueryCommand; | ||
nin(val: any[]): DatabaseQueryCommand; | ||
class DatabaseQueryCommand extends DatabaseLogicCommand { | ||
operator: QUERY_COMMANDS_LITERAL | string | ||
geoNear(options: IGeoNearCommandOptions): DatabaseQueryCommand; | ||
geoWithin(options: IGeoWithinCommandOptions): DatabaseQueryCommand; | ||
geoIntersects(options: IGeoIntersectsCommandOptions): DatabaseQueryCommand; | ||
_setFieldName(fieldName: string): DatabaseQueryCommand | ||
and( | ||
...expressions: (DatabaseLogicCommand | IQueryCondition)[] | ||
): DatabaseLogicCommand; | ||
or( | ||
...expressions: (DatabaseLogicCommand | IQueryCondition)[] | ||
): DatabaseLogicCommand; | ||
eq(val: any): DatabaseLogicCommand | ||
neq(val: any): DatabaseLogicCommand | ||
gt(val: any): DatabaseLogicCommand | ||
gte(val: any): DatabaseLogicCommand | ||
lt(val: any): DatabaseLogicCommand | ||
lte(val: any): DatabaseLogicCommand | ||
in(val: any[]): DatabaseLogicCommand | ||
nin(val: any[]): DatabaseLogicCommand | ||
set(val: any): DatabaseUpdateCommand; | ||
remove(): DatabaseUpdateCommand; | ||
inc(val: number): DatabaseUpdateCommand; | ||
mul(val: number): DatabaseUpdateCommand; | ||
geoNear(options: IGeoNearCommandOptions): DatabaseLogicCommand | ||
geoWithin(options: IGeoWithinCommandOptions): DatabaseLogicCommand | ||
geoIntersects( | ||
options: IGeoIntersectsCommandOptions, | ||
): DatabaseLogicCommand | ||
} | ||
push(...values: any[]): DatabaseUpdateCommand; | ||
pop(): DatabaseUpdateCommand; | ||
shift(): DatabaseUpdateCommand; | ||
unshift(...values: any[]): DatabaseUpdateCommand; | ||
} | ||
enum UPDATE_COMMANDS_LITERAL { | ||
SET = 'set', | ||
REMOVE = 'remove', | ||
INC = 'inc', | ||
MUL = 'mul', | ||
PUSH = 'push', | ||
POP = 'pop', | ||
SHIFT = 'shift', | ||
UNSHIFT = 'unshift', | ||
} | ||
export enum LOGIC_COMMANDS_LITERAL { | ||
AND = 'and', | ||
OR = 'or', | ||
NOT = 'not', | ||
NOR = 'nor', | ||
} | ||
class DatabaseUpdateCommand { | ||
fieldName: string | InternalSymbol | ||
operator: UPDATE_COMMANDS_LITERAL | ||
operands: any[] | ||
export class DatabaseLogicCommand { | ||
public fieldName: string | InternalSymbol; | ||
public operator: LOGIC_COMMANDS_LITERAL | string; | ||
public operands: any[]; | ||
constructor( | ||
operator: UPDATE_COMMANDS_LITERAL, | ||
operands: any[], | ||
fieldName?: string | InternalSymbol, | ||
) | ||
_setFieldName(fieldName: string): DatabaseLogicCommand; | ||
_setFieldName(fieldName: string): DatabaseUpdateCommand | ||
} | ||
and( | ||
...expressions: (DatabaseLogicCommand | IQueryCondition)[] | ||
): DatabaseLogicCommand; | ||
or( | ||
...expressions: (DatabaseLogicCommand | IQueryCondition)[] | ||
): DatabaseLogicCommand; | ||
} | ||
class Batch {} | ||
export enum QUERY_COMMANDS_LITERAL { | ||
// normal | ||
EQ = 'eq', | ||
NEQ = 'neq', | ||
GT = 'gt', | ||
GTE = 'gte', | ||
LT = 'lt', | ||
LTE = 'lte', | ||
IN = 'in', | ||
NIN = 'nin', | ||
// geo | ||
GEO_NEAR = 'geoNear', | ||
GEO_WITHIN = 'geoWithin', | ||
GEO_INTERSECTS = 'geoIntersects', | ||
} | ||
export class DatabaseQueryCommand extends DatabaseLogicCommand { | ||
public operator: QUERY_COMMANDS_LITERAL | string; | ||
_setFieldName(fieldName: string): DatabaseQueryCommand; | ||
eq(val: any): DatabaseLogicCommand; | ||
neq(val: any): DatabaseLogicCommand; | ||
gt(val: any): DatabaseLogicCommand; | ||
gte(val: any): DatabaseLogicCommand; | ||
lt(val: any): DatabaseLogicCommand; | ||
lte(val: any): DatabaseLogicCommand; | ||
in(val: any[]): DatabaseLogicCommand; | ||
nin(val: any[]): DatabaseLogicCommand; | ||
geoNear(options: IGeoNearCommandOptions): DatabaseLogicCommand; | ||
geoWithin(options: IGeoWithinCommandOptions): DatabaseLogicCommand; | ||
geoIntersects(options: IGeoIntersectsCommandOptions): DatabaseLogicCommand; | ||
} | ||
export enum UPDATE_COMMANDS_LITERAL { | ||
SET = 'set', | ||
REMOVE = 'remove', | ||
INC = 'inc', | ||
MUL = 'mul', | ||
PUSH = 'push', | ||
POP = 'pop', | ||
SHIFT = 'shift', | ||
UNSHIFT = 'unshift', | ||
} | ||
export class DatabaseUpdateCommand { | ||
public fieldName: string | InternalSymbol; | ||
public operator: UPDATE_COMMANDS_LITERAL; | ||
public operands: any[]; | ||
constructor( | ||
operator: UPDATE_COMMANDS_LITERAL, | ||
operands: any[], | ||
fieldName?: string | InternalSymbol, | ||
); | ||
_setFieldName(fieldName: string): DatabaseUpdateCommand; | ||
} | ||
export class Batch {} | ||
/** | ||
* A contract that all API provider must adhere to | ||
*/ | ||
export class APIBaseContract< | ||
PROMISE_RETURN, | ||
CALLBACK_RETURN, | ||
PARAM extends IAPIParam, | ||
CONTEXT = any | ||
> { | ||
getContext(param: PARAM): CONTEXT; | ||
/** | ||
* In case of callback-style invocation, this function will be called | ||
* A contract that all API provider must adhere to | ||
*/ | ||
getCallbackReturn(param: PARAM, context: CONTEXT): CALLBACK_RETURN; | ||
class APIBaseContract< | ||
PROMISE_RETURN, | ||
CALLBACK_RETURN, | ||
PARAM extends IAPIParam, | ||
CONTEXT = any | ||
> { | ||
getContext(param: PARAM): CONTEXT | ||
getFinalParam<T extends PARAM>(param: PARAM, context: CONTEXT): T; | ||
/** | ||
* In case of callback-style invocation, this function will be called | ||
*/ | ||
getCallbackReturn(param: PARAM, context: CONTEXT): CALLBACK_RETURN | ||
run<T extends PARAM>(param: T): Promise<PROMISE_RETURN>; | ||
} | ||
getFinalParam<T extends PARAM>(param: PARAM, context: CONTEXT): T | ||
export interface IGeoPointConstructor { | ||
new (longitude: number, latitide: number): GeoPoint; | ||
new (geojson: IGeoJSONPoint): GeoPoint; | ||
(longitude: number, latitide: number): GeoPoint; | ||
(geojson: IGeoJSONPoint): GeoPoint; | ||
} | ||
run<T extends PARAM>(param: T): Promise<PROMISE_RETURN> | ||
} | ||
export interface IGeoMultiPointConstructor { | ||
new (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint; | ||
(points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint; | ||
} | ||
interface IGeoPointConstructor { | ||
new (longitude: number, latitide: number): GeoPoint | ||
new (geojson: IGeoJSONPoint): GeoPoint | ||
(longitude: number, latitide: number): GeoPoint | ||
(geojson: IGeoJSONPoint): GeoPoint | ||
} | ||
export interface IGeoLineStringConstructor { | ||
new (points: GeoPoint[] | IGeoJSONLineString): GeoLineString; | ||
(points: GeoPoint[] | IGeoJSONLineString): GeoLineString; | ||
} | ||
interface IGeoMultiPointConstructor { | ||
new (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint | ||
(points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint | ||
} | ||
export interface IGeoMultiLineStringConstructor { | ||
new ( | ||
lineStrings: GeoLineString[] | IGeoJSONMultiLineString, | ||
): GeoMultiLineString; | ||
( | ||
lineStrings: GeoLineString[] | IGeoJSONMultiLineString, | ||
): GeoMultiLineString; | ||
} | ||
interface IGeoLineStringConstructor { | ||
new (points: GeoPoint[] | IGeoJSONLineString): GeoLineString | ||
(points: GeoPoint[] | IGeoJSONLineString): GeoLineString | ||
} | ||
export interface IGeoPolygonConstructor { | ||
new (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon; | ||
(lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon; | ||
} | ||
interface IGeoMultiLineStringConstructor { | ||
new ( | ||
lineStrings: GeoLineString[] | IGeoJSONMultiLineString, | ||
): GeoMultiLineString | ||
( | ||
lineStrings: GeoLineString[] | IGeoJSONMultiLineString, | ||
): GeoMultiLineString | ||
} | ||
export interface IGeoMultiPolygonConstructor { | ||
new (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon; | ||
(polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon; | ||
} | ||
interface IGeoPolygonConstructor { | ||
new (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon | ||
(lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon | ||
} | ||
export interface IGeo { | ||
Point: IGeoPointConstructor; | ||
MultiPoint: IGeoMultiPointConstructor; | ||
LineString: IGeoLineStringConstructor; | ||
MultiLineString: IGeoMultiLineStringConstructor; | ||
Polygon: IGeoPolygonConstructor; | ||
MultiPolygon: IGeoMultiPolygonConstructor; | ||
} | ||
interface IGeoMultiPolygonConstructor { | ||
new (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon | ||
(polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon | ||
} | ||
export interface IGeoJSONPoint { | ||
type: 'Point'; | ||
coordinates: [number, number]; | ||
} | ||
interface IGeo { | ||
Point: IGeoPointConstructor | ||
MultiPoint: IGeoMultiPointConstructor | ||
LineString: IGeoLineStringConstructor | ||
MultiLineString: IGeoMultiLineStringConstructor | ||
Polygon: IGeoPolygonConstructor | ||
MultiPolygon: IGeoMultiPolygonConstructor | ||
} | ||
export interface IGeoJSONMultiPoint { | ||
type: 'MultiPoint'; | ||
coordinates: [number, number][]; | ||
} | ||
interface IGeoJSONPoint { | ||
type: 'Point' | ||
coordinates: [number, number] | ||
} | ||
export interface IGeoJSONLineString { | ||
type: 'LineString'; | ||
coordinates: [number, number][]; | ||
} | ||
interface IGeoJSONMultiPoint { | ||
type: 'MultiPoint' | ||
coordinates: Array<[number, number]> | ||
} | ||
export interface IGeoJSONMultiLineString { | ||
type: 'MultiLineString'; | ||
coordinates: [number, number][][]; | ||
} | ||
interface IGeoJSONLineString { | ||
type: 'LineString' | ||
coordinates: Array<[number, number]> | ||
} | ||
export interface IGeoJSONPolygon { | ||
type: 'Polygon'; | ||
coordinates: [number, number][][]; | ||
} | ||
interface IGeoJSONMultiLineString { | ||
type: 'MultiLineString' | ||
coordinates: Array<Array<[number, number]>> | ||
} | ||
export interface IGeoJSONMultiPolygon { | ||
type: 'MultiPolygon'; | ||
coordinates: [number, number][][][]; | ||
} | ||
interface IGeoJSONPolygon { | ||
type: 'Polygon' | ||
coordinates: Array<Array<[number, number]>> | ||
} | ||
export type IGeoJSONObject = | ||
| IGeoJSONPoint | ||
| IGeoJSONMultiPoint | ||
| IGeoJSONLineString | ||
| IGeoJSONMultiLineString | ||
| IGeoJSONPolygon | ||
| IGeoJSONMultiPolygon; | ||
interface IGeoJSONMultiPolygon { | ||
type: 'MultiPolygon' | ||
coordinates: Array<Array<Array<[number, number]>>> | ||
} | ||
export abstract class GeoPoint { | ||
public longitude: number; | ||
public latitude: number; | ||
type IGeoJSONObject = | ||
| IGeoJSONPoint | ||
| IGeoJSONMultiPoint | ||
| IGeoJSONLineString | ||
| IGeoJSONMultiLineString | ||
| IGeoJSONPolygon | ||
| IGeoJSONMultiPolygon | ||
constructor(longitude: number, latitude: number); | ||
abstract class GeoPoint { | ||
longitude: number | ||
latitude: number | ||
toJSON(): object; | ||
toString(): string; | ||
} | ||
constructor(longitude: number, latitude: number) | ||
export abstract class GeoMultiPoint { | ||
public points: GeoPoint[]; | ||
toJSON(): object | ||
toString(): string | ||
} | ||
constructor(points: GeoPoint[]); | ||
abstract class GeoMultiPoint { | ||
points: GeoPoint[] | ||
toJSON(): IGeoJSONMultiPoint; | ||
toString(): string; | ||
} | ||
constructor(points: GeoPoint[]) | ||
export abstract class GeoLineString { | ||
public points: GeoPoint[]; | ||
toJSON(): IGeoJSONMultiPoint | ||
toString(): string | ||
} | ||
constructor(points: GeoPoint[]); | ||
abstract class GeoLineString { | ||
points: GeoPoint[] | ||
toJSON(): IGeoJSONLineString; | ||
toString(): string; | ||
} | ||
constructor(points: GeoPoint[]) | ||
export abstract class GeoMultiLineString { | ||
public lines: GeoLineString[]; | ||
toJSON(): IGeoJSONLineString | ||
toString(): string | ||
} | ||
constructor(lines: GeoLineString[]); | ||
abstract class GeoMultiLineString { | ||
lines: GeoLineString[] | ||
toJSON(): IGeoJSONMultiLineString; | ||
toString(): string; | ||
} | ||
constructor(lines: GeoLineString[]) | ||
export abstract class GeoPolygon { | ||
public lines: GeoLineString[]; | ||
toJSON(): IGeoJSONMultiLineString | ||
toString(): string | ||
} | ||
constructor(lines: GeoLineString[]); | ||
abstract class GeoPolygon { | ||
lines: GeoLineString[] | ||
toJSON(): IGeoJSONPolygon; | ||
toString(): string; | ||
} | ||
constructor(lines: GeoLineString[]) | ||
export abstract class GeoMultiPolygon { | ||
public polygons: GeoPolygon[]; | ||
toJSON(): IGeoJSONPolygon | ||
toString(): string | ||
} | ||
constructor(polygons: GeoPolygon[]); | ||
abstract class GeoMultiPolygon { | ||
polygons: GeoPolygon[] | ||
toJSON(): IGeoJSONMultiPolygon; | ||
toString(): string; | ||
} | ||
constructor(polygons: GeoPolygon[]) | ||
export type GeoInstance = | ||
| GeoPoint | ||
| GeoMultiPoint | ||
| GeoLineString | ||
| GeoMultiLineString | ||
| GeoPolygon | ||
| GeoMultiPolygon; | ||
toJSON(): IGeoJSONMultiPolygon | ||
toString(): string | ||
} | ||
export interface IGeoNearCommandOptions { | ||
geometry: GeoPoint; | ||
maxDistance?: number; | ||
minDistance?: number; | ||
} | ||
type GeoInstance = | ||
| GeoPoint | ||
| GeoMultiPoint | ||
| GeoLineString | ||
| GeoMultiLineString | ||
| GeoPolygon | ||
| GeoMultiPolygon | ||
export interface IGeoWithinCommandOptions { | ||
geometry: GeoPolygon | GeoMultiPolygon; | ||
} | ||
interface IGeoNearCommandOptions { | ||
geometry: GeoPoint | ||
maxDistance?: number | ||
minDistance?: number | ||
} | ||
export interface IGeoIntersectsCommandOptions { | ||
geometry: | ||
| GeoPoint | ||
| GeoMultiPoint | ||
| GeoLineString | ||
| GeoMultiLineString | ||
| GeoPolygon | ||
| GeoMultiPolygon; | ||
} | ||
interface IGeoWithinCommandOptions { | ||
geometry: GeoPolygon | GeoMultiPolygon | ||
} | ||
export interface IServerDateOptions { | ||
offset: number; | ||
} | ||
interface IGeoIntersectsCommandOptions { | ||
geometry: | ||
| GeoPoint | ||
| GeoMultiPoint | ||
| GeoLineString | ||
| GeoMultiLineString | ||
| GeoPolygon | ||
| GeoMultiPolygon | ||
} | ||
export abstract class ServerDate { | ||
public readonly options: IServerDateOptions; | ||
constructor(options?: IServerDateOptions); | ||
} | ||
interface IServerDateOptions { | ||
offset: number | ||
} | ||
export interface IRegExpOptions { | ||
regexp: string; | ||
options?: string; | ||
} | ||
abstract class ServerDate { | ||
readonly options: IServerDateOptions | ||
constructor(options?: IServerDateOptions) | ||
} | ||
export interface IRegExpConstructor { | ||
new (options: IRegExpOptions): RegExp; | ||
(options: IRegExpOptions): RegExp; | ||
} | ||
interface IRegExpOptions { | ||
regexp: string | ||
options?: string | ||
} | ||
export abstract class RegExp { | ||
public readonly regexp: string; | ||
public readonly options: string; | ||
constructor(options: IRegExpOptions); | ||
} | ||
interface IRegExpConstructor { | ||
new (options: IRegExpOptions): RegExp | ||
(options: IRegExpOptions): RegExp | ||
} | ||
export type DocumentId = string | number; | ||
abstract class RegExp { | ||
readonly regexp: string | ||
readonly options: string | ||
constructor(options: IRegExpOptions) | ||
} | ||
export interface IDocumentData { | ||
_id?: DocumentId; | ||
[key: string]: any; | ||
} | ||
type DocumentId = string | number | ||
export interface IDBAPIParam extends IAPIParam {} | ||
interface IDocumentData { | ||
_id?: DocumentId | ||
[key: string]: any | ||
} | ||
export interface IAddDocumentOptions extends IDBAPIParam { | ||
data: IDocumentData; | ||
} | ||
type IDBAPIParam = IAPIParam | ||
export interface IGetDocumentOptions extends IDBAPIParam {} | ||
interface IAddDocumentOptions extends IDBAPIParam { | ||
data: IDocumentData | ||
} | ||
export interface ICountDocumentOptions extends IDBAPIParam {} | ||
type IGetDocumentOptions = IDBAPIParam | ||
export interface IUpdateDocumentOptions extends IDBAPIParam { | ||
data: IUpdateCondition; | ||
} | ||
type ICountDocumentOptions = IDBAPIParam | ||
export interface IUpdateSingleDocumentOptions extends IDBAPIParam { | ||
data: IUpdateCondition; | ||
} | ||
interface IUpdateDocumentOptions extends IDBAPIParam { | ||
data: IUpdateCondition | ||
} | ||
export interface ISetDocumentOptions extends IDBAPIParam { | ||
data: IUpdateCondition; | ||
} | ||
interface IUpdateSingleDocumentOptions extends IDBAPIParam { | ||
data: IUpdateCondition | ||
} | ||
export interface ISetSingleDocumentOptions extends IDBAPIParam { | ||
data: IUpdateCondition; | ||
} | ||
interface ISetDocumentOptions extends IDBAPIParam { | ||
data: IUpdateCondition | ||
} | ||
export interface IRemoveDocumentOptions extends IDBAPIParam { | ||
query: IQueryCondition; | ||
} | ||
interface ISetSingleDocumentOptions extends IDBAPIParam { | ||
data: IUpdateCondition | ||
} | ||
export interface IRemoveSingleDocumentOptions extends IDBAPIParam {} | ||
interface IRemoveDocumentOptions extends IDBAPIParam { | ||
query: IQueryCondition | ||
} | ||
export interface IQueryCondition { | ||
[key: string]: any; | ||
} | ||
type IRemoveSingleDocumentOptions = IDBAPIParam | ||
export type IStringQueryCondition = string; | ||
interface IQueryCondition { | ||
[key: string]: any | ||
} | ||
export interface IQueryResult extends IAPISuccessParam { | ||
data: IDocumentData[]; | ||
} | ||
type IStringQueryCondition = string | ||
export interface IQuerySingleResult extends IAPISuccessParam { | ||
data: IDocumentData; | ||
} | ||
interface IQueryResult extends IAPISuccessParam { | ||
data: IDocumentData[] | ||
} | ||
export interface IUpdateCondition { | ||
[key: string]: any; | ||
} | ||
interface IQuerySingleResult extends IAPISuccessParam { | ||
data: IDocumentData | ||
} | ||
export type IStringUpdateCondition = string; | ||
interface IUpdateCondition { | ||
[key: string]: any | ||
} | ||
export interface ISetCondition {} | ||
type IStringUpdateCondition = string | ||
export interface IAddResult extends IAPISuccessParam { | ||
_id: DocumentId; | ||
} | ||
interface IAddResult extends IAPISuccessParam { | ||
_id: DocumentId | ||
} | ||
export interface IUpdateResult extends IAPISuccessParam { | ||
stats: { | ||
updated: number; | ||
// created: number, | ||
}; | ||
} | ||
interface IUpdateResult extends IAPISuccessParam { | ||
stats: { | ||
updated: number, | ||
// created: number, | ||
} | ||
} | ||
export interface ISetResult extends IAPISuccessParam { | ||
_id: DocumentId; | ||
stats: { | ||
updated: number; | ||
created: number; | ||
}; | ||
} | ||
interface ISetResult extends IAPISuccessParam { | ||
_id: DocumentId | ||
stats: { | ||
updated: number | ||
created: number, | ||
} | ||
} | ||
export interface IRemoveResult extends IAPISuccessParam { | ||
stats: { | ||
removed: number; | ||
}; | ||
} | ||
interface IRemoveResult extends IAPISuccessParam { | ||
stats: { | ||
removed: number, | ||
} | ||
} | ||
export interface ICountResult extends IAPISuccessParam { | ||
total: number; | ||
} | ||
interface ICountResult extends IAPISuccessParam { | ||
total: number | ||
} | ||
} | ||
type Optional<T> = { [K in keyof T]+?: T[K] }; | ||
type Optional<T> = { [K in keyof T]+?: T[K] } | ||
type OQ< | ||
T extends Optional< | ||
Record<'complete' | 'success' | 'fail', (...args: any[]) => any> | ||
> | ||
T extends Optional< | ||
Record<'complete' | 'success' | 'fail', (...args: any[]) => any> | ||
> | ||
> = | ||
| (RQ<T> & Required<Pick<T, 'success'>>) | ||
| (RQ<T> & Required<Pick<T, 'fail'>>) | ||
| (RQ<T> & Required<Pick<T, 'complete'>>) | ||
| (RQ<T> & Required<Pick<T, 'success' | 'fail'>>) | ||
| (RQ<T> & Required<Pick<T, 'success' | 'complete'>>) | ||
| (RQ<T> & Required<Pick<T, 'fail' | 'complete'>>) | ||
| (RQ<T> & Required<Pick<T, 'fail' | 'complete' | 'success'>>); | ||
| (RQ<T> & Required<Pick<T, 'success'>>) | ||
| (RQ<T> & Required<Pick<T, 'fail'>>) | ||
| (RQ<T> & Required<Pick<T, 'complete'>>) | ||
| (RQ<T> & Required<Pick<T, 'success' | 'fail'>>) | ||
| (RQ<T> & Required<Pick<T, 'success' | 'complete'>>) | ||
| (RQ<T> & Required<Pick<T, 'fail' | 'complete'>>) | ||
| (RQ<T> & Required<Pick<T, 'fail' | 'complete' | 'success'>>) | ||
type RQ< | ||
T extends Optional< | ||
Record<'complete' | 'success' | 'fail', (...args: any[]) => any> | ||
> | ||
> = Pick<T, Exclude<keyof T, 'complete' | 'success' | 'fail'>>; | ||
T extends Optional< | ||
Record<'complete' | 'success' | 'fail', (...args: any[]) => any> | ||
> | ||
> = Pick<T, Exclude<keyof T, 'complete' | 'success' | 'fail'>> |
/*! ***************************************************************************** | ||
Copyright (c) 2018 Tencent, Inc. All rights reserved. | ||
Copyright (c) 2019 Tencent, Inc. All rights reserved. | ||
@@ -11,197 +11,363 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
/*! ***************************************************************************** | ||
Copyright (c) 2018 Tencent, Inc. All rights reserved. | ||
declare namespace WechatMiniprogram { | ||
namespace Component { | ||
type Instance< | ||
TData extends DataOption, | ||
TProperty extends PropertyOption, | ||
TMethod extends MethodOption | ||
> = InstanceProperties & | ||
InstanceMethods<TData> & | ||
TMethod & { | ||
/** 组件数据,**包括内部数据和属性值** */ | ||
data: TData & PropertyOptionToData<TProperty> | ||
/** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */ | ||
properties: TData & PropertyOptionToData<TProperty>, | ||
} | ||
type TrivialInstance = Instance<IAnyObject, IAnyObject, IAnyObject> | ||
type TrivialOption = Options<IAnyObject, IAnyObject, IAnyObject> | ||
type Options< | ||
TData extends DataOption, | ||
TProperty extends PropertyOption, | ||
TMethod extends MethodOption | ||
> = Partial<Data<TData>> & | ||
Partial<Property<TProperty>> & | ||
Partial<Method<TMethod>> & | ||
Partial<OtherOption> & | ||
Partial<Lifetimes> & | ||
ThisType<Instance<TData, TProperty, TMethod>> | ||
interface Constructor { | ||
< | ||
TData extends DataOption, | ||
TProperty extends PropertyOption, | ||
TMethod extends MethodOption | ||
>( | ||
options: Options<TData, TProperty, TMethod>, | ||
): string | ||
} | ||
type DataOption = Record<string, any> | ||
type PropertyOption = Record<string, AllProperty> | ||
type MethodOption = Record<string, (...args: any[]) => any> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
interface Data<D extends DataOption> { | ||
/** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */ | ||
data?: D | ||
} | ||
interface Property<P extends PropertyOption> { | ||
/** 组件的对外属性,是属性名到属性设置的映射表 */ | ||
properties: P | ||
} | ||
interface Method<M extends MethodOption> { | ||
/** object组件的方法,包括事件响应函数和任意的自定义方法,关于事件响应函数的使用,参见 [组件事件](events.md) */ | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
methods: M | ||
} | ||
type PropertyType = | ||
| StringConstructor | ||
| NumberConstructor | ||
| BooleanConstructor | ||
| ArrayConstructor | ||
| ObjectConstructor | ||
| null | ||
type ValueType<T extends PropertyType> = T extends StringConstructor | ||
? string | ||
: T extends NumberConstructor | ||
? number | ||
: T extends BooleanConstructor | ||
? boolean | ||
: T extends ArrayConstructor | ||
? any[] | ||
: T extends ObjectConstructor ? object : any | ||
interface FullProperty<T extends PropertyType> { | ||
/** 属性类型 */ | ||
type: T | ||
/** 属性初始值 */ | ||
value?: ValueType<T> | ||
/** 属性值被更改时的响应函数 */ | ||
observer?( | ||
newVal: ValueType<T>, | ||
oldVal: ValueType<T>, | ||
changedPath: Array<string | number>, | ||
): void | ||
/** 属性的类型(可以指定多个) */ | ||
optionalTypes?: ShortProperty[] | ||
} | ||
type AllFullProperty = | ||
| FullProperty<StringConstructor> | ||
| FullProperty<NumberConstructor> | ||
| FullProperty<BooleanConstructor> | ||
| FullProperty<ArrayConstructor> | ||
| FullProperty<ObjectConstructor> | ||
| FullProperty<null> | ||
type ShortProperty = | ||
| StringConstructor | ||
| NumberConstructor | ||
| BooleanConstructor | ||
| ArrayConstructor | ||
| ObjectConstructor | ||
| null | ||
type AllProperty = AllFullProperty | ShortProperty | ||
type PropertyToData<T extends AllProperty> = T extends ShortProperty | ||
? ValueType<T> | ||
: FullPropertyToData<Exclude<T, ShortProperty>> | ||
type FullPropertyToData<T extends AllFullProperty> = ValueType< | ||
T['type'] | ||
> | ||
type PropertyOptionToData<P extends PropertyOption> = { | ||
[name in keyof P]: PropertyToData<P[name]> | ||
} | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
***************************************************************************** */ | ||
interface InstanceProperties { | ||
/** 组件的文件路径 */ | ||
is: string | ||
/** 节点id */ | ||
id: string | ||
/** 节点dataset */ | ||
dataset: Record<string, string> | ||
} | ||
type PropertyType = | ||
| StringConstructor | ||
| NumberConstructor | ||
| BooleanConstructor | ||
| ObjectConstructor | ||
| ArrayConstructor | ||
| null; | ||
interface InstanceMethods<D extends DataOption> { | ||
/** `setData` 函数用于将数据从逻辑层发送到视图层 | ||
*(异步),同时改变对应的 `this.data` 的值(同步)。 | ||
* | ||
* **注意:** | ||
* | ||
* 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。 | ||
* 1. 仅支持设置可 JSON 化的数据。 | ||
* 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。 | ||
* 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。 | ||
*/ | ||
setData( | ||
/** 这次要改变的数据 | ||
* | ||
* 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。 | ||
* | ||
* 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。 | ||
*/ | ||
data: Partial<D> & IAnyObject, | ||
/** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */ | ||
callback?: () => void, | ||
): void | ||
declare interface PropertyOption { | ||
/** 属性类型 */ | ||
type: PropertyType; | ||
/** 属性初始值 */ | ||
value?: any; | ||
/** 属性值被更改时的响应函数 */ | ||
observer?( | ||
newVal?: any, | ||
oldVal?: any, | ||
changedPath?: Array<string | number>, | ||
): void; | ||
optionalTypes?: PropertyType[]; | ||
} | ||
/** 检查组件是否具有 `behavior` (检查时会递归检查被直接或间接引入的所有behavior) */ | ||
hasBehavior(behavior: object): void | ||
/** 触发事件,参见组件事件 */ | ||
triggerEvent( | ||
name: string, | ||
detail?: object, | ||
options?: TriggerEventOption, | ||
): void | ||
/** 创建一个 SelectorQuery 对象,选择器选取范围为这个组件实例内 */ | ||
createSelectorQuery(): SelectorQuery | ||
/** 创建一个 IntersectionObserver 对象,选择器选取范围为这个组件实例内 */ | ||
createIntersectionObserver( | ||
options: CreateIntersectionObserverOption, | ||
): IntersectionObserver | ||
/** 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象(会被 `wx://component-export` 影响) */ | ||
selectComponent(selector: string): TrivialInstance | ||
/** 使用选择器选择组件实例节点,返回匹配到的全部组件实例对象组成的数组 */ | ||
selectAllComponents(selector: string): TrivialInstance[] | ||
/** 获取这个关系所对应的所有关联节点,参见 组件间关系 */ | ||
getRelationNodes(relationKey: string): TrivialInstance[] | ||
/** 立刻执行 callback ,其中的多个 setData 之间不会触发界面绘制(只有某些特殊场景中需要,如用于在不同组件同时 setData 时进行界面绘制同步)*/ | ||
groupSetData(callback?: () => void): void | ||
/** 返回当前页面的 custom-tab-bar 的组件实例 */ | ||
getTabBar(): TrivialInstance | ||
/** 返回页面标识符(一个字符串),可以用来判断几个自定义组件实例是不是在同一个页面内 */ | ||
getPageId(): string | ||
} | ||
declare interface TriggerEventOption { | ||
/** 事件是否冒泡 | ||
* | ||
* 默认值: `false` | ||
*/ | ||
bubbles?: boolean; | ||
/** 事件是否可以穿越组件边界,为false时,事件将只能在引用组件的节点树上触发,不进入其他任何组件内部 | ||
* | ||
* 默认值: `false` | ||
*/ | ||
composed?: boolean; | ||
/** 事件是否拥有捕获阶段 | ||
* | ||
* 默认值: `false` | ||
*/ | ||
capturePhase?: boolean; | ||
} | ||
interface ComponentOptions { | ||
/** | ||
* [启用多slot支持](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件wxml的slot) | ||
*/ | ||
multipleSlots?: boolean | ||
/** | ||
* [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离) | ||
*/ | ||
addGlobalClass?: boolean | ||
/** | ||
* [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离) | ||
*/ | ||
styleIsolation?: | ||
| 'isolated' | ||
| 'apply-shared' | ||
| 'shared' | ||
| 'page-isolated' | ||
| 'page-apply-shared' | ||
| 'page-shared' | ||
} | ||
declare interface WxComponent extends BaseComponent { | ||
/** 组件的文件路径 */ | ||
is: string; | ||
/** 节点id */ | ||
id: string; | ||
/** 节点dataset */ | ||
dataset: string; | ||
/** 组件数据,**包括内部数据和属性值** */ | ||
data: object; | ||
/** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */ | ||
properties: { | ||
[propertyName: string]: PropertyOption; | ||
}; | ||
interface TriggerEventOption { | ||
/** 事件是否冒泡 | ||
* | ||
* 默认值: `false` | ||
*/ | ||
bubbles?: boolean | ||
/** 事件是否可以穿越组件边界,为false时,事件将只能在引用组件的节点树上触发,不进入其他任何组件内部 | ||
* | ||
* 默认值: `false` | ||
*/ | ||
composed?: boolean | ||
/** 事件是否拥有捕获阶段 | ||
* | ||
* 默认值: `false` | ||
*/ | ||
capturePhase?: boolean | ||
} | ||
/** 设置data并执行视图层渲染 */ | ||
setData( | ||
/** 这次要改变的数据 | ||
* | ||
* 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。 | ||
* | ||
* 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。 | ||
*/ | ||
data: object, | ||
/** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */ | ||
callback?: (data: object) => void, | ||
): void; | ||
/** 检查组件是否具有 `behavior` (检查时会递归检查被直接或间接引入的所有behavior) */ | ||
hasBehavior(behavior: object): void; | ||
/** 触发事件,参见组件事件 */ | ||
triggerEvent( | ||
name: string, | ||
detail?: object, | ||
options?: TriggerEventOption, | ||
): void; | ||
/** 创建一个 SelectorQuery 对象,选择器选取范围为这个组件实例内 */ | ||
createSelectorQuery(): WechatMiniprogram.SelectorQuery; | ||
/** 创建一个 IntersectionObserver 对象,选择器选取范围为这个组件实例内 */ | ||
createIntersectionObserver( | ||
options: WechatMiniprogram.CreateIntersectionObserverOption, | ||
): WechatMiniprogram.IntersectionObserver; | ||
/** 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象(会被 `wx://component-export` 影响) */ | ||
selectComponent(selector: string): WxComponent; | ||
/** 使用选择器选择组件实例节点,返回匹配到的全部组件实例对象组成的数组 */ | ||
selectAllComponents(selector: string): WxComponent[]; | ||
/** 获取这个关系所对应的所有关联节点,参见 组件间关系 */ | ||
getRelationNodes(relationKey: string): WxComponent[]; | ||
/** 立刻执行 callback ,其中的多个 setData 之间不会触发界面绘制(只有某些特殊场景中需要,如用于在不同组件同时 setData 时进行界面绘制同步)*/ | ||
groupSetData(callback?: () => void): void; | ||
/** 返回当前页面的 custom-tab-bar 的组件实例 */ | ||
getTabBar(): WxComponent; | ||
} | ||
interface RelationOption { | ||
/** 目标组件的相对关系 */ | ||
type: 'parent' | 'child' | 'ancestor' | 'descendant' | ||
/** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */ | ||
linked?(target: TrivialInstance): void | ||
/** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */ | ||
linkChanged?(target: TrivialInstance): void | ||
/** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */ | ||
unlinked?(target: TrivialInstance): void | ||
/** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */ | ||
target?: string | ||
} | ||
declare interface ComponentLifetimes { | ||
/** 组件生命周期函数,在组件实例进入页面节点树时执行,注意此时不能调用 `setData` */ | ||
created?(this: WxComponent): void; | ||
/** 组件生命周期函数,在组件实例进入页面节点树时执行 */ | ||
attached?(this: WxComponent): void; | ||
/** 组件生命周期函数,在组件布局完成后执行,此时可以获取节点信息(使用 [SelectorQuery]((SelectorQuery))) */ | ||
ready?(this: WxComponent): void; | ||
/** 组件生命周期函数,在组件实例被移动到节点树另一个位置时执行 */ | ||
moved?(this: WxComponent): void; | ||
/** 组件生命周期函数,在组件实例被从页面节点树移除时执行 */ | ||
detached?(this: WxComponent): void; | ||
/** 组件生命周期函数,每当组件方法抛出错误时执行 */ | ||
error?(error: Error): void; | ||
} | ||
interface PageLifetimes { | ||
/** 页面生命周期回调—监听页面显示 | ||
* | ||
* 页面显示/切入前台时触发。 | ||
*/ | ||
show(): void | ||
/** 页面生命周期回调—监听页面隐藏 | ||
* | ||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。 | ||
*/ | ||
hide(): void | ||
/** 页面生命周期回调—监听页面尺寸变化 | ||
* | ||
* 所在页面尺寸变化时执行 | ||
*/ | ||
resize(size: Page.IResizeOption): void | ||
} | ||
declare interface PageLifetimes { | ||
/** 页面生命周期回调—监听页面显示 | ||
* | ||
* 页面显示/切入前台时触发。 | ||
*/ | ||
show?(this: Page.PageInstance): void; | ||
/** 页面生命周期回调—监听页面隐藏 | ||
* | ||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。 | ||
*/ | ||
hide?(this: Page.PageInstance): void; | ||
/** 页面生命周期回调—监听页面尺寸变化 | ||
* | ||
* 所在页面尺寸变化时执行 | ||
*/ | ||
resize?(Size?: Page.IResizeOption): void; | ||
} | ||
type DefinitionFilter = <T extends TrivialOption>( | ||
/** 使用该 behavior 的 component/behavior 的定义对象 */ | ||
defFields: T, | ||
/** 该 behavior 所使用的 behavior 的 definitionFilter 函数列表 */ | ||
definitionFilterArr?: DefinitionFilter[], | ||
) => void | ||
declare interface RelationOption { | ||
/** 目标组件的相对关系 */ | ||
type: 'parent' | 'child' | 'ancestor' | 'descendant'; | ||
/** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */ | ||
linked?(target: WxComponent): any; | ||
/** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */ | ||
linkChanged?(target: WxComponent): any; | ||
/** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */ | ||
unlinked?(target: WxComponent): any; | ||
/** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */ | ||
target?: string; | ||
} | ||
interface Lifetimes { | ||
/** 组件生命周期声明对象,组件的生命周期:`created`、`attached`、`ready`、`moved`、`detached` 将收归到 `lifetimes` 字段内进行声明,原有声明方式仍旧有效,如同时存在两种声明方式,则 `lifetimes` 字段内声明方式优先级最高 | ||
* | ||
* 最低基础库: `2.2.3` */ | ||
lifetimes: Partial<{ | ||
/** | ||
* 在组件实例刚刚被创建时执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
created(): void | ||
/** | ||
* 在组件实例进入页面节点树时执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
attached(): void | ||
/** | ||
* 在组件在视图层布局完成后执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
ready(): void | ||
/** | ||
* 在组件实例被移动到节点树另一个位置时执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
moved(): void | ||
/** | ||
* 在组件实例被从页面节点树移除时执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
detached(): void | ||
/** | ||
* 每当组件方法抛出错误时执行 | ||
* | ||
* 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
error(err: Error): void, | ||
}> | ||
/** | ||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义 | ||
* | ||
* 在组件实例刚刚被创建时执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
created(): void | ||
/** | ||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义 | ||
* | ||
* 在组件实例进入页面节点树时执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
attached(): void | ||
/** | ||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义 | ||
* | ||
* 在组件在视图层布局完成后执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
ready(): void | ||
/** | ||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义 | ||
* | ||
* 在组件实例被移动到节点树另一个位置时执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
moved(): void | ||
/** | ||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义 | ||
* | ||
* 在组件实例被从页面节点树移除时执行 | ||
* | ||
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
detached(): void | ||
/** | ||
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义 | ||
* | ||
* 每当组件方法抛出错误时执行 | ||
* | ||
* 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) | ||
*/ | ||
error(err: Error): void | ||
} | ||
type DefinitionFilter = ( | ||
defFields: WxComponent, | ||
definitionFilterArr?: DefinitionFilter[], | ||
) => void; | ||
interface OtherOption { | ||
/** 类似于mixins和traits的组件间代码复用机制,参见 [behaviors](behaviors.md) */ | ||
behaviors: string[] | ||
/** 组件数据字段监听器,用于监听 properties 和 data 的变化 */ | ||
observers: Record<string, (...args: any[]) => any> | ||
/** 组件间关系定义,参见 [组件间关系](relations.md) */ | ||
relations: { | ||
[componentName: string]: RelationOption, | ||
} | ||
/** 组件接受的外部样式类,参见 [外部样式类](wxml-wxss.md) */ | ||
externalClasses?: string[] | ||
/** 组件所在页面的生命周期声明对象,目前仅支持页面的 `show` 和 `hide` 两个生命周期 | ||
* | ||
* 最低基础库: `2.2.3` */ | ||
pageLifetimes?: Partial<PageLifetimes> | ||
/** 一些选项(文档中介绍相关特性时会涉及具体的选项设置,这里暂不列举) */ | ||
options: ComponentOptions | ||
declare interface ComponentOptions { | ||
multipleSlots?: boolean; | ||
addGlobalClass?: boolean; | ||
/** 定义段过滤器,用于自定义组件扩展,参见 [自定义组件扩展](extend.md) | ||
* | ||
* 最低基础库: `2.2.3` */ | ||
definitionFilter?: DefinitionFilter | ||
} | ||
} | ||
} | ||
declare interface BaseComponent extends ComponentLifetimes { | ||
/** 组件的对外属性,是属性名到属性设置的映射表 */ | ||
properties?: { | ||
[propertyName: string]: PropertyOption; | ||
}; | ||
/** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */ | ||
data?: object; | ||
/** 组件数据字段监听器,用于监听 properties 和 data 的变化 */ | ||
observers?: object; | ||
/** object组件的方法,包括事件响应函数和任意的自定义方法,关于事件响应函数的使用,参见 [组件事件](events.md) */ | ||
methods?: { | ||
[methodName: string]: (this: WxComponent) => any; | ||
}; | ||
/** 类似于mixins和traits的组件间代码复用机制,参见 [behaviors](behaviors.md) */ | ||
behaviors?: string[]; | ||
/** 组件间关系定义,参见 [组件间关系](relations.md) */ | ||
relations?: { | ||
[componentName: string]: RelationOption; | ||
}; | ||
/** 组件接受的外部样式类,参见 [外部样式类](wxml-wxss.md) */ | ||
externalClasses?: string[]; | ||
/** 一些选项(文档中介绍相关特性时会涉及具体的选项设置,这里暂不列举) */ | ||
options?: ComponentOptions; | ||
/** 组件生命周期声明对象,组件的生命周期:`created`、`attached`、`ready`、`moved`、`detached` 将收归到 `lifetimes` 字段内进行声明,原有声明方式仍旧有效,如同时存在两种声明方式,则 `lifetimes` 字段内声明方式优先级最高 | ||
* | ||
* 最低基础库: `2.2.3` */ | ||
lifetimes?: ComponentLifetimes; | ||
/** 组件所在页面的生命周期声明对象,目前仅支持页面的 `show` 和 `hide` 两个生命周期 | ||
* | ||
* 最低基础库: `2.2.3` */ | ||
pageLifetimes?: PageLifetimes; | ||
/** 定义段过滤器,用于自定义组件扩展,参见 [自定义组件扩展](extend.md) | ||
* | ||
* 最低基础库: `2.2.3` */ | ||
definitionFilter?: DefinitionFilter; | ||
} | ||
/** Component构造器可用于定义组件,调用Component构造器时可以指定组件的属性、数据、方法等。 | ||
@@ -216,4 +382,2 @@ * | ||
*/ | ||
declare function Component( | ||
/** 自定义组件注册参数 */ options: BaseComponent, | ||
): void; | ||
declare const Component: WechatMiniprogram.Component.Constructor |
/*! ***************************************************************************** | ||
Copyright (c) 2018 Tencent, Inc. All rights reserved. | ||
Copyright (c) 2019 Tencent, Inc. All rights reserved. | ||
@@ -11,203 +11,201 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
/*! ***************************************************************************** | ||
Copyright (c) 2018 Tencent, Inc. All rights reserved. | ||
declare namespace WechatMiniprogram { | ||
namespace Page { | ||
type Instance< | ||
TData extends DataOption, | ||
TCustom extends CustomOption | ||
> = OptionalInterface<ILifetime> & | ||
InstanceProperties & | ||
InstanceMethods<TData> & | ||
Data<TData> & | ||
TCustom | ||
type Options< | ||
TData extends DataOption, | ||
TCustom extends CustomOption | ||
> = (TCustom & Partial<Data<TData>> & Partial<ILifetime>) & | ||
ThisType<Instance<TData, TCustom>> | ||
type TrivialInstance = Instance<IAnyObject, IAnyObject> | ||
interface Constructor { | ||
<TData extends DataOption, TCustom extends CustomOption>( | ||
options: Options<TData, TCustom>, | ||
): void | ||
} | ||
interface ILifetime { | ||
/** 生命周期回调—监听页面加载 | ||
* | ||
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。 | ||
*/ | ||
onLoad( | ||
/** 打开当前页面路径中的参数 */ | ||
query: Record<string, string | undefined>, | ||
): void | ||
/** 生命周期回调—监听页面显示 | ||
* | ||
* 页面显示/切入前台时触发。 | ||
*/ | ||
onShow(): void | ||
/** 生命周期回调—监听页面初次渲染完成 | ||
* | ||
* 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。 | ||
* | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* 注意:对界面内容进行设置的 API 如`wx.setNavigationBarTitle`,请在`onReady`之后进行。 | ||
*/ | ||
onReady(): void | ||
/** 生命周期回调—监听页面隐藏 | ||
* | ||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。 | ||
*/ | ||
onHide(): void | ||
/** 生命周期回调—监听页面卸载 | ||
* | ||
* 页面卸载时触发。如`redirectTo`或`navigateBack`到其他页面时。 | ||
*/ | ||
onUnload(): void | ||
/** 监听用户下拉动作 | ||
* | ||
* 监听用户下拉刷新事件。 | ||
* - 需要在`app.json`的`window`选项中或页面配置中开启`enablePullDownRefresh`。 | ||
* - 可以通过`wx.startPullDownRefresh`触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。 | ||
* - 当处理完数据刷新后,`wx.stopPullDownRefresh`可以停止当前页面的下拉刷新。 | ||
*/ | ||
onPullDownRefresh(): void | ||
/** 页面上拉触底事件的处理函数 | ||
* | ||
* 监听用户上拉触底事件。 | ||
* - 可以在`app.json`的`window`选项中或页面配置中设置触发距离`onReachBottomDistance`。 | ||
* - 在触发距离内滑动期间,本事件只会被触发一次。 | ||
*/ | ||
onReachBottom(): void | ||
/** 用户点击右上角转发 | ||
* | ||
* 监听用户点击页面内转发按钮(`<button>` 组件 `open-type="share"`)或右上角菜单“转发”按钮的行为,并自定义转发内容。 | ||
* | ||
* **注意:只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮** | ||
* | ||
* 此事件需要 return 一个 Object,用于自定义转发内容 | ||
*/ | ||
onShareAppMessage( | ||
/** 分享发起来源参数 */ | ||
options: IShareAppMessageOption, | ||
): ICustomShareContent | ||
/** 页面滚动触发事件的处理函数 | ||
* | ||
* 监听用户滑动页面事件。 | ||
*/ | ||
onPageScroll( | ||
/** 页面滚动参数 */ | ||
options: IPageScrollOption, | ||
): void | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
/** 当前是 tab 页时,点击 tab 时触发,最低基础库: `1.9.0` */ | ||
onTabItemTap( | ||
/** tab 点击参数 */ | ||
options: ITabItemTapOption, | ||
): void | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
***************************************************************************** */ | ||
/** 窗口尺寸改变时触发,最低基础库:`2.4.0` */ | ||
onResize( | ||
/** 窗口尺寸参数 */ | ||
options: IResizeOption, | ||
): void | ||
} | ||
interface InstanceProperties { | ||
/** 页面的文件路径 */ | ||
is: string | ||
declare namespace Page { | ||
interface ICustomShareContent { | ||
/** 转发标题。默认值:当前小程序名称 */ | ||
title?: string; | ||
/** 转发路径,必须是以 / 开头的完整路径。默认值:当前页面 path */ | ||
path?: string; | ||
/** 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持PNG及JPG。显示图片长宽比是 5:4,最低基础库: `1.5.0`。默认值:使用默认截图 */ | ||
imageUrl?: string; | ||
} | ||
/** 到当前页面的路径 */ | ||
route: string | ||
} | ||
interface IPageScrollOption { | ||
/** 页面在垂直方向已滚动的距离(单位px) */ | ||
scrollTop: number; | ||
} | ||
type DataOption = Record<string, any> | ||
type CustomOption = Record<string, any> | ||
interface IShareAppMessageOption { | ||
/** 转发事件来源。 | ||
* | ||
* 可选值: | ||
* - `button`:页面内转发按钮; | ||
* - `menu`:右上角转发菜单。 | ||
* | ||
* 最低基础库: `1.2.4` | ||
*/ | ||
from: 'button' | 'menu' | string; | ||
/** 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined` | ||
* | ||
* 最低基础库: `1.2.4` */ | ||
target: any; | ||
/** 页面中包含`<web-view>`组件时,返回当前`<web-view>`的url | ||
* | ||
* 最低基础库: `1.6.4` | ||
*/ | ||
webViewUrl?: string; | ||
} | ||
type InstanceMethods<D extends DataOption> = Component.InstanceMethods< | ||
D | ||
> | ||
interface ITabItemTapOption { | ||
/** 被点击tabItem的序号,从0开始,最低基础库: `1.9.0` */ | ||
index: string; | ||
/** 被点击tabItem的页面路径,最低基础库: `1.9.0` */ | ||
pagePath: string; | ||
/** 被点击tabItem的按钮文字,最低基础库: `1.9.0` */ | ||
text: string; | ||
} | ||
interface Data<D extends DataOption> { | ||
/** 页面的初始数据 | ||
* | ||
* `data` 是页面第一次渲染使用的**初始数据**。 | ||
* | ||
* 页面加载时,`data` 将会以`JSON`字符串的形式由逻辑层传至渲染层,因此`data`中的数据必须是可以转成`JSON`的类型:字符串,数字,布尔值,对象,数组。 | ||
* | ||
* 渲染层可以通过 `WXML` 对数据进行绑定。 | ||
*/ | ||
data: D | ||
} | ||
interface IResizeOption { | ||
size: { | ||
/** 变化后的窗口宽度,单位 px */ | ||
windowWidth: number; | ||
/** 变化后的窗口高度,单位 px */ | ||
windowHeight: number; | ||
}; | ||
} | ||
interface ICustomShareContent { | ||
/** 转发标题。默认值:当前小程序名称 */ | ||
title?: string | ||
/** 转发路径,必须是以 / 开头的完整路径。默认值:当前页面 path */ | ||
path?: string | ||
/** 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持PNG及JPG。显示图片长宽比是 5:4,最低基础库: `1.5.0`。默认值:使用默认截图 */ | ||
imageUrl?: string | ||
} | ||
interface PageInstanceBaseProps<D extends IAnyObject = any> { | ||
/** 页面的初始数据 | ||
* | ||
* `data` 是页面第一次渲染使用的**初始数据**。 | ||
* | ||
* 页面加载时,`data` 将会以`JSON`字符串的形式由逻辑层传至渲染层,因此`data`中的数据必须是可以转成`JSON`的类型:字符串,数字,布尔值,对象,数组。 | ||
* | ||
* 渲染层可以通过 `WXML` 对数据进行绑定。 | ||
*/ | ||
data?: D; | ||
interface IPageScrollOption { | ||
/** 页面在垂直方向已滚动的距离(单位px) */ | ||
scrollTop: number | ||
} | ||
/** `setData` 函数用于将数据从逻辑层发送到视图层(异步),同时改变对应的 `this.data` 的值(同步)。 | ||
* | ||
* **注意:** | ||
* | ||
* 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。 | ||
* 1. 仅支持设置可 JSON 化的数据。 | ||
* 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。 | ||
* 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。 | ||
*/ | ||
interface IShareAppMessageOption { | ||
/** 转发事件来源。 | ||
* | ||
* 可选值: | ||
* - `button`:页面内转发按钮; | ||
* - `menu`:右上角转发菜单。 | ||
* | ||
* 最低基础库: `1.2.4` | ||
*/ | ||
from: 'button' | 'menu' | string | ||
/** 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined` | ||
* | ||
* 最低基础库: `1.2.4` */ | ||
target: any | ||
/** 页面中包含`<web-view>`组件时,返回当前`<web-view>`的url | ||
* | ||
* 最低基础库: `1.6.4` | ||
*/ | ||
webViewUrl?: string | ||
} | ||
setData?<K extends keyof D>( | ||
/** 这次要改变的数据 | ||
* | ||
* 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。 | ||
* | ||
* 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。 | ||
*/ | ||
data: D | Pick<D, K> | IAnyObject, | ||
/** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */ | ||
callback?: () => void, | ||
): void; | ||
interface ITabItemTapOption { | ||
/** 被点击tabItem的序号,从0开始,最低基础库: `1.9.0` */ | ||
index: string | ||
/** 被点击tabItem的页面路径,最低基础库: `1.9.0` */ | ||
pagePath: string | ||
/** 被点击tabItem的按钮文字,最低基础库: `1.9.0` */ | ||
text: string | ||
} | ||
/** 到当前页面的路径,类型为`String`。最低基础库: `1.2.0` */ | ||
route?: string; | ||
} | ||
interface IResizeOption { | ||
size: { | ||
/** 变化后的窗口宽度,单位 px */ | ||
windowWidth: number | ||
/** 变化后的窗口高度,单位 px */ | ||
windowHeight: number, | ||
} | ||
} | ||
interface PageInstance< | ||
D extends IAnyObject = any, | ||
T extends IAnyObject = any | ||
> extends PageInstanceBaseProps<D> { | ||
/** 生命周期回调—监听页面加载 | ||
* | ||
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。 | ||
*/ | ||
onLoad?( | ||
/** 打开当前页面路径中的参数 */ | ||
query?: { [queryKey: string]: string }, | ||
): void; | ||
/** 生命周期回调—监听页面显示 | ||
* | ||
* 页面显示/切入前台时触发。 | ||
*/ | ||
onShow?(): void; | ||
/** 生命周期回调—监听页面初次渲染完成 | ||
* | ||
* 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。 | ||
* | ||
* 注意:对界面内容进行设置的 API 如`wx.setNavigationBarTitle`,请在`onReady`之后进行。 | ||
*/ | ||
onReady?(): void; | ||
/** 生命周期回调—监听页面隐藏 | ||
* | ||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。 | ||
*/ | ||
onHide?(): void; | ||
/** 生命周期回调—监听页面卸载 | ||
* | ||
* 页面卸载时触发。如`redirectTo`或`navigateBack`到其他页面时。 | ||
*/ | ||
onUnload?(): void; | ||
/** 监听用户下拉动作 | ||
* | ||
* 监听用户下拉刷新事件。 | ||
* - 需要在`app.json`的`window`选项中或页面配置中开启`enablePullDownRefresh`。 | ||
* - 可以通过`wx.startPullDownRefresh`触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。 | ||
* - 当处理完数据刷新后,`wx.stopPullDownRefresh`可以停止当前页面的下拉刷新。 | ||
*/ | ||
onPullDownRefresh?(): void; | ||
/** 页面上拉触底事件的处理函数 | ||
* | ||
* 监听用户上拉触底事件。 | ||
* - 可以在`app.json`的`window`选项中或页面配置中设置触发距离`onReachBottomDistance`。 | ||
* - 在触发距离内滑动期间,本事件只会被触发一次。 | ||
*/ | ||
onReachBottom?(): void; | ||
/** 用户点击右上角转发 | ||
* | ||
* 监听用户点击页面内转发按钮(`<button>` 组件 `open-type="share"`)或右上角菜单“转发”按钮的行为,并自定义转发内容。 | ||
* | ||
* **注意:只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮** | ||
* | ||
* 此事件需要 return 一个 Object,用于自定义转发内容 | ||
*/ | ||
onShareAppMessage?( | ||
/** 分享发起来源参数 */ | ||
options?: IShareAppMessageOption, | ||
): ICustomShareContent; | ||
/** 页面滚动触发事件的处理函数 | ||
* | ||
* 监听用户滑动页面事件。 | ||
*/ | ||
onPageScroll?( | ||
/** 页面滚动参数 */ | ||
options?: IPageScrollOption, | ||
): void; | ||
interface getCurrentPages { | ||
(): Array<Instance<IAnyObject, IAnyObject>> | ||
} | ||
} | ||
} | ||
/** 当前是 tab 页时,点击 tab 时触发,最低基础库: `1.9.0` */ | ||
onTabItemTap?( | ||
/** tab 点击参数 */ | ||
options?: ITabItemTapOption, | ||
): void; | ||
/** | ||
* 注册小程序中的一个页面。接受一个 `Object` 类型参数,其指定页面的初始数据、生命周期回调、事件处理函数等。 | ||
*/ | ||
declare const Page: WechatMiniprogram.Page.Constructor | ||
/** | ||
* 获取当前页面栈。数组中第一个元素为首页,最后一个元素为当前页面。 | ||
/** 窗口尺寸改变时触发,最低基础库:`2.4.0` */ | ||
onResize?( | ||
/** 窗口尺寸参数 */ | ||
options?: IResizeOption, | ||
): void; | ||
} | ||
* __注意:__ | ||
interface PageConstructor { | ||
<D extends IAnyObject, T extends IAnyObject & PageInstance>( | ||
options: PageInstance<D, T> & T, | ||
): void; | ||
} | ||
interface GetCurrentPages { | ||
<D extends IAnyObject = {}, T extends IAnyObject = {}>(): (PageInstance< | ||
D, | ||
T | ||
> & | ||
T)[]; | ||
} | ||
} | ||
declare const Page: Page.PageConstructor; | ||
declare const getCurrentPages: Page.GetCurrentPages; | ||
* - __不要尝试修改页面栈,会导致路由以及页面状态错误。__ | ||
* - 不要在 `App.onLaunch` 的时候调用 `getCurrentPages()`,此时 `page` 还没有生成。 | ||
*/ | ||
declare const getCurrentPages: WechatMiniprogram.Page.getCurrentPages |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
695034
15
16004
37
1