Merge branch '1.2.0' of https://github.com/IvinWu/weRequest into 1.2.0
# Conflicts: # build/weRequest.js # build/weRequest.min.js # package.json # src/module/errorHandler.ts # src/module/requestHandler.ts # src/module/responseHandler.ts
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.idea
|
||||
.DS_Store
|
||||
node_modules/
|
||||
package-lock.json
|
||||
8
build/api/getConfig.d.ts
vendored
Normal file
8
build/api/getConfig.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export interface IGetConfigResult {
|
||||
urlPerfix?: string | (() => string);
|
||||
sessionExpireTime?: number;
|
||||
sessionExpireKey?: string;
|
||||
sessionExpire?: number;
|
||||
}
|
||||
declare const _default: () => IGetConfigResult;
|
||||
export default _default;
|
||||
2
build/api/getSession.d.ts
vendored
Normal file
2
build/api/getSession.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: () => any;
|
||||
export default _default;
|
||||
29
build/api/init.d.ts
vendored
Normal file
29
build/api/init.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/// <reference types="wx" />
|
||||
export interface IInitOption {
|
||||
codeToSession: ICodeToSessionOptions;
|
||||
sessionName: string;
|
||||
urlPerfix?: string | (() => string);
|
||||
doNotCheckSession?: boolean;
|
||||
reLoginLimit?: number;
|
||||
errorCallback?: null | Function;
|
||||
reportCGI?: boolean | ((name: string, startTime: number, endTime: number, request?: () => void) => void);
|
||||
mockJson?: TODO;
|
||||
globalData?: boolean | object | Function;
|
||||
sessionExpireKey: string;
|
||||
loginTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||
successTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||
successData?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||
errorTitle?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
||||
errorContent?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
||||
}
|
||||
export interface ICodeToSessionOptions {
|
||||
url?: string;
|
||||
method?: 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT' | 'string';
|
||||
codeName?: string;
|
||||
data?: string | IAnyObject | ArrayBuffer;
|
||||
success?: Function;
|
||||
fail?: Function;
|
||||
report?: string;
|
||||
}
|
||||
declare const _default: (params: IInitOption) => void;
|
||||
export default _default;
|
||||
2
build/api/login.d.ts
vendored
Normal file
2
build/api/login.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: (callback: Function) => void;
|
||||
export default _default;
|
||||
7
build/api/request.d.ts
vendored
Normal file
7
build/api/request.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface IRequestOption extends wx.RequestOption {
|
||||
beforeSend?: Function;
|
||||
showLoading?: boolean | string;
|
||||
report?: string;
|
||||
}
|
||||
declare const _default: (obj: IRequestOption) => void;
|
||||
export default _default;
|
||||
2
build/api/setSession.d.ts
vendored
Normal file
2
build/api/setSession.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: (session: any) => void;
|
||||
export default _default;
|
||||
2
build/api/uploadFile.d.ts
vendored
Normal file
2
build/api/uploadFile.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: (obj: any) => void;
|
||||
export default _default;
|
||||
24
build/index.d.ts
vendored
Normal file
24
build/index.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { IInitOption } from "./api/init";
|
||||
import { IRequestOption } from "./api/request";
|
||||
export interface IUploadFileOption extends wx.UploadFileOption {
|
||||
beforeSend?: Function;
|
||||
showLoading?: boolean | string;
|
||||
report?: string;
|
||||
}
|
||||
export interface IGetConfigResult {
|
||||
urlPerfix?: string | (() => string);
|
||||
sessionExpireTime?: number;
|
||||
sessionExpireKey?: string;
|
||||
sessionExpire?: number;
|
||||
}
|
||||
export interface weRequest {
|
||||
init?: (obj: IInitOption) => void;
|
||||
request?: (option: IRequestOption) => void;
|
||||
uploadFile?: (option: IUploadFileOption) => void;
|
||||
getSession?: () => string;
|
||||
getConfig?: () => IGetConfigResult;
|
||||
login?: (callback: Function) => void;
|
||||
setSession?: (x: string) => void;
|
||||
}
|
||||
declare const weRequestObject: weRequest;
|
||||
export default weRequestObject;
|
||||
8
build/module/cacheManager.d.ts
vendored
Normal file
8
build/module/cacheManager.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference types="wx" />
|
||||
declare function get(obj: TODO): void;
|
||||
declare function set(obj: TODO, realData: TODO): void;
|
||||
declare const _default: {
|
||||
get: typeof get;
|
||||
set: typeof set;
|
||||
};
|
||||
export default _default;
|
||||
8
build/module/durationReporter.d.ts
vendored
Normal file
8
build/module/durationReporter.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference types="wx" />
|
||||
declare function start(obj: TODO, name?: string): void;
|
||||
declare function end(obj: TODO, name?: string): void;
|
||||
declare const _default: {
|
||||
start: typeof start;
|
||||
end: typeof end;
|
||||
};
|
||||
export default _default;
|
||||
2
build/module/errorHandler.d.ts
vendored
Normal file
2
build/module/errorHandler.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: (obj: any, res: any) => void;
|
||||
export default _default;
|
||||
6
build/module/mockManager.d.ts
vendored
Normal file
6
build/module/mockManager.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/// <reference types="wx" />
|
||||
declare function get(obj: TODO, method: "request" | "uploadFile"): any;
|
||||
declare const _default: {
|
||||
get: typeof get;
|
||||
};
|
||||
export default _default;
|
||||
8
build/module/requestHandler.d.ts
vendored
Normal file
8
build/module/requestHandler.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference types="wx" />
|
||||
declare function request(obj: TODO): TODO;
|
||||
declare function uploadFile(obj: TODO): TODO;
|
||||
declare const _default: {
|
||||
request: typeof request;
|
||||
uploadFile: typeof uploadFile;
|
||||
};
|
||||
export default _default;
|
||||
3
build/module/responseHandler.d.ts
vendored
Normal file
3
build/module/responseHandler.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/// <reference types="wx" />
|
||||
declare function response(res: wx.RequestSuccessCallbackResult | wx.UploadFileSuccessCallbackResult, obj: TODO, method: "request" | "uploadFile"): any;
|
||||
export default response;
|
||||
3
build/module/sessionManager.d.ts
vendored
Normal file
3
build/module/sessionManager.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/// <reference types="wx" />
|
||||
declare function checkSession(callback: Function, obj: TODO): void;
|
||||
export default checkSession;
|
||||
3
build/store/config.d.ts
vendored
Normal file
3
build/store/config.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { IInitOption } from '../api/init';
|
||||
declare const defaultConfig: IInitOption;
|
||||
export default defaultConfig;
|
||||
2
build/store/status.d.ts
vendored
Normal file
2
build/store/status.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: any;
|
||||
export default _default;
|
||||
8
build/util/flow.d.ts
vendored
Normal file
8
build/util/flow.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference types="wx" />
|
||||
declare function emit(key: TODO): void;
|
||||
declare function wait(key: TODO, callback: Function): void;
|
||||
declare const _default: {
|
||||
wait: typeof wait;
|
||||
emit: typeof emit;
|
||||
};
|
||||
export default _default;
|
||||
7
build/util/loading.d.ts
vendored
Normal file
7
build/util/loading.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
declare function show(txt: boolean | string): void;
|
||||
declare function hide(): void;
|
||||
declare const _default: {
|
||||
show: typeof show;
|
||||
hide: typeof hide;
|
||||
};
|
||||
export default _default;
|
||||
5
build/util/url.d.ts
vendored
Normal file
5
build/util/url.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare function setParams(url: string, params: object): string;
|
||||
declare const _default: {
|
||||
setParams: typeof setParams;
|
||||
};
|
||||
export default _default;
|
||||
1044
build/weRequest.js
1044
build/weRequest.js
File diff suppressed because one or more lines are too long
4
build/weRequest.min.js
vendored
4
build/weRequest.min.js
vendored
File diff suppressed because one or more lines are too long
4233
package-lock.json
generated
Normal file
4233
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "we-request",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"description": "本工具通过拓展小程序的wx.request,让开发者通过简单的配置,实现自动管理登录态等功能",
|
||||
"keywords": [
|
||||
"登录态",
|
||||
@@ -19,14 +19,25 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/IvinWu/weRequest.git"
|
||||
},
|
||||
"main": "./src/index.js",
|
||||
"main": "build/weRequest.js",
|
||||
"typings": "build/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "webpack"
|
||||
},
|
||||
"dependencies": {
|
||||
"webpack": "latest"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"webpack-cli": "^2.1.3"
|
||||
"prettier": "^1.15.3",
|
||||
"pretty-quick": "^1.8.0",
|
||||
"ts-loader": "^5.3.1",
|
||||
"tslint": "^5.12.0",
|
||||
"tslint-config-prettier": "^1.17.0",
|
||||
"typescript": "^3.2.2",
|
||||
"webpack": "^4.28.0",
|
||||
"webpack-cli": "^3.1.1"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "pretty-quick --staged"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
renameJsFile.js
Normal file
17
renameJsFile.js
Normal file
@@ -0,0 +1,17 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
dir = './src/util',
|
||||
match = RegExp('.js', 'g'),
|
||||
replace = '.ts',
|
||||
files;
|
||||
|
||||
files = fs.readdirSync(dir);
|
||||
|
||||
files.filter(function(file) {
|
||||
return file.match(match);
|
||||
}).forEach(function(file) {
|
||||
var filePath = path.join(dir, file),
|
||||
newFilePath = path.join(dir, file.replace(match, replace));
|
||||
console.log({filePath, newFilePath})
|
||||
fs.renameSync(filePath, newFilePath);
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
import config from '../store/config'
|
||||
import status from '../store/status'
|
||||
|
||||
export default () => {
|
||||
return {
|
||||
urlPerfix: config.urlPerfix,
|
||||
sessionExpireTime: status.sessionExpireTime,
|
||||
sessionExpireKey: config.sessionExpireKey,
|
||||
sessionExpire: status.sessionExpire
|
||||
}
|
||||
};
|
||||
23
src/api/getConfig.ts
Normal file
23
src/api/getConfig.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import config from '../store/config'
|
||||
import status from '../store/status'
|
||||
|
||||
export interface IGetConfigResult{
|
||||
/* 在组件初始化时传入的请求URL的固定前缀 */
|
||||
urlPerfix?: string | (() => string);
|
||||
/* 在组件初始化时传入的用户登陆态设置本地缓存时间 */
|
||||
sessionExpireTime?: number;
|
||||
/* 在组件初始化时传入的用户登陆态本地缓存时间Storage的key */
|
||||
sessionExpireKey?: string;
|
||||
/* 用户登陆态本地缓存过期的时间戳 */
|
||||
sessionExpire?: number;
|
||||
}
|
||||
|
||||
export default () => {
|
||||
const configResult :IGetConfigResult = {
|
||||
urlPerfix: config.urlPerfix,
|
||||
sessionExpireTime: status.sessionExpireTime,
|
||||
sessionExpireKey: config.sessionExpireKey,
|
||||
sessionExpire: status.sessionExpire
|
||||
}
|
||||
return configResult;
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
import config from '../store/config'
|
||||
import status from '../store/status'
|
||||
|
||||
export default (params) => {
|
||||
Object.assign(config, params);
|
||||
// 如果配置更改了session的存储名字,则重新获取一次session
|
||||
if (params.sessionName) {
|
||||
try {
|
||||
status.session = wx.getStorageSync(config.sessionName) || '';
|
||||
} catch (e) {
|
||||
console.error('wx.getStorageSync:fail, can not get session.')
|
||||
}
|
||||
}
|
||||
// 如果配置更改了session过期时间的存储名字,则重新获取一次session的过期时间
|
||||
if (params.sessionExpireKey) {
|
||||
try {
|
||||
status.sessionExpire = wx.getStorageSync(config.sessionExpireKey) || Infinity;
|
||||
} catch (e) {
|
||||
console.error('wx.getStorageSync:fail, can not get sessionExpire.')
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/api/init.ts
Normal file
89
src/api/init.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import defaultConfig from '../store/config'
|
||||
import status from '../store/status'
|
||||
|
||||
export interface IInitOption {
|
||||
/* 用code换取session的CGI配置 */
|
||||
codeToSession: ICodeToSessionOptions;
|
||||
/* 储存在localStorage的session名称,且CGI请求的data中会自动带上以此为名称的session值;可不配置,默认为session */
|
||||
sessionName: string;
|
||||
/* 请求URL的固定前缀,如果配置了,后续请求的URL都会自动加上这个前缀,如果是函数,则为函数的返回值 */
|
||||
urlPerfix?: string | (() => string);
|
||||
/* 是否需要调用checkSession,验证小程序的登录态过期;若业务不需要使用到session_key,则可配置为true */
|
||||
doNotCheckSession?: boolean;
|
||||
/* 登录重试次数,当连续请求登录接口返回失败次数超过这个次数,将不再重试登录 */
|
||||
reLoginLimit?: number;
|
||||
/* 当出现接口逻辑错误时,会执行统一的回调函数,这里可以做统一的错误上报等处理 */
|
||||
errorCallback?: null | Function;
|
||||
/* 接口返回成功之后,会执行统一的回调函数,这里可以做统一的耗时上报等处理 */
|
||||
reportCGI?: boolean | ((
|
||||
/* 调用的接口名字,可在request接口的report字段配置 */
|
||||
name: string,
|
||||
/* 发起请求时的时间戳 */
|
||||
startTime: number,
|
||||
/* 请求返回时的时间戳 */
|
||||
endTime: number,
|
||||
/* 请求方法,可用于上报 */
|
||||
request?: () => void
|
||||
) => void);
|
||||
/* 可为接口提供mock数据 */
|
||||
mockJson?: TODO;
|
||||
/** 所有请求都会自动带上这里的参数 */
|
||||
globalData?: boolean | object | Function;
|
||||
/** session在本地缓存的key */
|
||||
sessionExpireKey: string;
|
||||
/* 触发重新登录的条件;参数为CGI返回的数据,返回需要重新登录的条件 */
|
||||
loginTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||
/* 触发请求成功的条件;参数为CGI返回的数据,返回接口逻辑成功的条件 */
|
||||
successTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||
/* 成功之后返回数据;参数为CGI返回的数据,返回逻辑需要使用的数据 */
|
||||
successData?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||
/* 接口逻辑失败时,错误弹窗的标题 */
|
||||
errorTitle?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
||||
/* 接口逻辑失败时,错误弹窗的内容 */
|
||||
errorContent?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
||||
}
|
||||
|
||||
export interface ICodeToSessionOptions{
|
||||
/* CGI的url */
|
||||
url?: string;
|
||||
/* 调用该CGI的方法 */
|
||||
method?: 'OPTIONS'
|
||||
| 'GET'
|
||||
| 'HEAD'
|
||||
| 'POST'
|
||||
| 'PUT'
|
||||
| 'DELETE'
|
||||
| 'TRACE'
|
||||
| 'CONNECT' | 'string',
|
||||
/* CGI中传参时,存放code的名称 */
|
||||
codeName?: string;
|
||||
/* 登录接口需要的其他参数 */
|
||||
data?: string | IAnyObject | ArrayBuffer;
|
||||
/* 接口返回成功的函数;需要返回session的值 */
|
||||
success?: Function;
|
||||
/* code换取session的接口逻辑出错时,执行的函数,若配置了此函数,则不再默认弹窗报错 */
|
||||
fail?: Function;
|
||||
/* codeToSession的上报字段名 */
|
||||
report?: string;
|
||||
}
|
||||
|
||||
|
||||
export default (params: IInitOption) => {
|
||||
const config: IInitOption = {...params, ...defaultConfig}
|
||||
// 如果配置更改了session的存储名字,则重新获取一次session
|
||||
if (params.sessionName) {
|
||||
try {
|
||||
status.session = wx.getStorageSync(config.sessionName!) || '';
|
||||
} catch (e) {
|
||||
console.error('wx.getStorageSync:fail, can not get session.')
|
||||
}
|
||||
}
|
||||
// 如果配置更改了session过期时间的存储名字,则重新获取一次session的过期时间
|
||||
if (params.sessionExpireKey) {
|
||||
try {
|
||||
status.sessionExpire = wx.getStorageSync(config.sessionExpireKey) || Infinity;
|
||||
} catch (e) {
|
||||
console.error('wx.getStorageSync:fail, can not get sessionExpire.')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import sessionManager from '../module/sessionManager'
|
||||
|
||||
export default (callback) => {
|
||||
sessionManager(callback, {})
|
||||
}
|
||||
5
src/api/login.ts
Normal file
5
src/api/login.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import checkSession from '../module/sessionManager'
|
||||
|
||||
export default (callback: Function) => {
|
||||
return checkSession(callback, {})
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import requestHandler from '../module/requestHandler'
|
||||
|
||||
export default (obj) => {
|
||||
requestHandler.request(obj)
|
||||
}
|
||||
14
src/api/request.ts
Normal file
14
src/api/request.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import requestHandler from '../module/requestHandler'
|
||||
|
||||
export interface IRequestOption extends wx.RequestOption {
|
||||
/* 发起请求前执行的函数 */
|
||||
beforeSend?: Function;
|
||||
/* 请求过程页面是否展示全屏的loading */
|
||||
showLoading?: boolean | string;
|
||||
/* 接口请求成功后将自动执行init()中配置的reportCGI函数,其中的name字段值为这里配置的值 */
|
||||
report?: string;
|
||||
}
|
||||
|
||||
export default (obj: IRequestOption) => {
|
||||
requestHandler.request(obj)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import status from '../store/status'
|
||||
|
||||
export default (session) => {
|
||||
export default (session: TODO) => {
|
||||
status.session = session;
|
||||
status.sessionIsFresh = true;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import requestHandler from '../module/requestHandler'
|
||||
|
||||
export default (obj) => {
|
||||
export default (obj: TODO) => {
|
||||
requestHandler.uploadFile(obj)
|
||||
}
|
||||
17
src/index.js
17
src/index.js
@@ -1,17 +0,0 @@
|
||||
import init from './api/init'
|
||||
import request from './api/request'
|
||||
import uploadFile from './api/uploadFile'
|
||||
import setSession from './api/setSession'
|
||||
import login from './api/login'
|
||||
import getSession from './api/getSession'
|
||||
import getConfig from './api/getConfig'
|
||||
|
||||
export {
|
||||
init,
|
||||
request,
|
||||
uploadFile,
|
||||
setSession,
|
||||
login,
|
||||
getSession,
|
||||
getConfig
|
||||
}
|
||||
58
src/index.ts
Normal file
58
src/index.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import init from "./api/init";
|
||||
import request from "./api/request";
|
||||
import uploadFile from "./api/uploadFile";
|
||||
import setSession from "./api/setSession";
|
||||
import login from "./api/login";
|
||||
import getSession from "./api/getSession";
|
||||
import getConfig from "./api/getConfig";
|
||||
import { IInitOption } from "./api/init";
|
||||
import { IRequestOption } from "./api/request";
|
||||
|
||||
export interface IUploadFileOption extends wx.UploadFileOption {
|
||||
/* 发起请求前执行的函数 */
|
||||
beforeSend?: Function;
|
||||
/* 请求过程页面是否展示全屏的loading */
|
||||
showLoading?: boolean | string;
|
||||
/* 接口请求成功后将自动执行init()中配置的reportCGI函数,其中的name字段值为这里配置的值 */
|
||||
report?: string;
|
||||
}
|
||||
|
||||
export interface IGetConfigResult {
|
||||
/* 在组件初始化时传入的请求URL的固定前缀 */
|
||||
urlPerfix?: string | (() => string);
|
||||
/* 在组件初始化时传入的用户登陆态设置本地缓存时间 */
|
||||
sessionExpireTime?: number;
|
||||
/* 在组件初始化时传入的用户登陆态本地缓存时间Storage的key */
|
||||
sessionExpireKey?: string;
|
||||
/* 用户登陆态本地缓存过期的时间戳 */
|
||||
sessionExpire?: number;
|
||||
}
|
||||
|
||||
export interface weRequest {
|
||||
/** 小程序账号信息 */
|
||||
init?: (obj: IInitOption) => void;
|
||||
/** 插件账号信息(仅在插件中调用时包含这一项) */
|
||||
request?: (option: IRequestOption) => void;
|
||||
/** 插件账号信息(仅在插件中调用时包含这一项) */
|
||||
uploadFile?: (option: IUploadFileOption) => void;
|
||||
/* 获取本地缓存中用户票据的值 */
|
||||
getSession?: () => string;
|
||||
/* 获取weRequest的配置 */
|
||||
getConfig?: () => IGetConfigResult;
|
||||
/* [不建议使用] 在不发起业务请求的情况下,单独执行登录逻辑 */
|
||||
login?: (callback: Function) => void;
|
||||
/* [不建议使用] 设置用户票据的值 */
|
||||
setSession?: (x: string) => void;
|
||||
}
|
||||
|
||||
const weRequestObject: weRequest = {
|
||||
init,
|
||||
request,
|
||||
uploadFile,
|
||||
setSession,
|
||||
login,
|
||||
getSession,
|
||||
getConfig
|
||||
};
|
||||
|
||||
export default weRequestObject;
|
||||
@@ -1,4 +1,4 @@
|
||||
function get(obj) {
|
||||
function get(obj: TODO) {
|
||||
wx.getStorage({
|
||||
key: obj.originUrl,
|
||||
success: function (res) {
|
||||
@@ -16,7 +16,7 @@ function get(obj) {
|
||||
})
|
||||
}
|
||||
|
||||
function set(obj, realData) {
|
||||
function set(obj: TODO , realData: TODO) {
|
||||
if (obj.cache === true || (typeof obj.cache === "function" && obj.cache(realData))) {
|
||||
wx.setStorage({
|
||||
key: obj.originUrl,
|
||||
@@ -1,6 +1,6 @@
|
||||
import config from '../store/config'
|
||||
|
||||
function start(obj, name) {
|
||||
function start(obj: TODO, name?: string) {
|
||||
switch (name) {
|
||||
case 'checkSession':
|
||||
obj._checkSessionStartTime = new Date().getTime();
|
||||
@@ -15,7 +15,7 @@ function start(obj, name) {
|
||||
}
|
||||
}
|
||||
|
||||
function end(obj, name) {
|
||||
function end(obj: TODO, name?: string) {
|
||||
switch (name) {
|
||||
case 'checkSession':
|
||||
// wx.checkSession 耗时上报
|
||||
@@ -1,14 +1,13 @@
|
||||
import config from '../store/config'
|
||||
|
||||
export default (obj, res) => {
|
||||
export default (obj: TODO, res: TODO) => {
|
||||
if (typeof obj.fail === "function") {
|
||||
obj.fail(res);
|
||||
} else {
|
||||
let title = "";
|
||||
if (typeof config.errorTitle === "function") {
|
||||
try {
|
||||
// TODO: 原生错误只有res.errMsg
|
||||
title = config.errorTitle(res.data)
|
||||
title = config.errorTitle(res.data || res.errMsg)
|
||||
} catch (e) {
|
||||
}
|
||||
} else if (typeof config.errorTitle === "string") {
|
||||
@@ -18,7 +17,7 @@ export default (obj, res) => {
|
||||
let content = "";
|
||||
if (typeof config.errorContent === "function") {
|
||||
try {
|
||||
content = config.errorContent(res.data)
|
||||
content = config.errorContent(res.data || res.errMsg)
|
||||
} catch (e) {
|
||||
}
|
||||
} else if (typeof config.errorContent === "string") {
|
||||
@@ -1,7 +1,7 @@
|
||||
import config from '../store/config'
|
||||
import responseHandler from './responseHandler'
|
||||
|
||||
function get(obj, method) {
|
||||
function get(obj: TODO, method: "request" | "uploadFile"): any {
|
||||
|
||||
if(!config.mockJson[obj.url] && !config.mockJson[obj.originUrl]) {
|
||||
// mock 没有对应接口的数据
|
||||
@@ -6,11 +6,11 @@ import cacheManager from './cacheManager'
|
||||
import sessionManager from './sessionManager'
|
||||
import errorHandler from './errorHandler'
|
||||
import responseHandler from './responseHandler'
|
||||
import durationReporter from './durationReporter'
|
||||
import durationReporter from "./durationReporter"
|
||||
import url from '../util/url'
|
||||
|
||||
// 格式化url
|
||||
function format(url) {
|
||||
function format(url: string) {
|
||||
if (url.startsWith('http')) {
|
||||
return url
|
||||
} else {
|
||||
@@ -23,8 +23,8 @@ function format(url) {
|
||||
}
|
||||
|
||||
// 所有请求发出前需要做的事情
|
||||
function preDo(obj) {
|
||||
if (typeof obj.beforeSend === "function") {
|
||||
function preDo(obj: TODO) {
|
||||
if(typeof obj.beforeSend === "function") {
|
||||
obj.beforeSend();
|
||||
}
|
||||
// 登录态失效,重复登录计数
|
||||
@@ -40,10 +40,12 @@ function preDo(obj) {
|
||||
|
||||
if (obj.showLoading) {
|
||||
loading.show(obj.showLoading);
|
||||
obj.complete = ((fn) => {
|
||||
return () => {
|
||||
obj.complete = ((fn: Function, ...args) => {
|
||||
return ()=> {
|
||||
// TODO 使用Promise方式后,可能不需要这些了
|
||||
loading.hide();
|
||||
typeof fn === "function" && fn.apply(this, arguments);
|
||||
// @ts-ignore
|
||||
typeof fn === "function" && fn.apply(this, ...args);
|
||||
}
|
||||
})(obj.complete)
|
||||
}
|
||||
@@ -57,17 +59,17 @@ function preDo(obj) {
|
||||
}
|
||||
|
||||
// 格式化处理请求的obj内容
|
||||
function initialize(obj, container) {
|
||||
function initialize(obj: TODO, container: TODO) {
|
||||
if (!obj[container]) {
|
||||
obj[container] = {};
|
||||
}
|
||||
|
||||
if (obj.originUrl !== config.codeToSession.url && status.session) {
|
||||
obj[container][config.sessionName] = status.session;
|
||||
obj[container][config.sessionName!] = status.session;
|
||||
}
|
||||
|
||||
// 如果有全局参数,则添加
|
||||
let gd = {};
|
||||
let gd: any = {};
|
||||
if (typeof config.globalData === "function") {
|
||||
gd = config.globalData();
|
||||
} else if (typeof config.globalData === "object") {
|
||||
@@ -81,7 +83,7 @@ function initialize(obj, container) {
|
||||
// 如果请求不是GET,则在URL中自动加上登录态和全局参数
|
||||
if (obj.method !== "GET") {
|
||||
if (status.session) {
|
||||
let params = {};
|
||||
let params: any = {};
|
||||
params[config.sessionName] = status.session;
|
||||
obj.url = url.setParams(obj.url, params);
|
||||
}
|
||||
@@ -93,7 +95,7 @@ function initialize(obj, container) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
function doRequest(obj) {
|
||||
function doRequest(obj: TODO) {
|
||||
obj = initialize(obj, 'data');
|
||||
obj.count++;
|
||||
wx.request({
|
||||
@@ -102,10 +104,10 @@ function doRequest(obj) {
|
||||
method: obj.method,
|
||||
header: obj.header || {},
|
||||
dataType: obj.dataType || 'json',
|
||||
success: function (res) {
|
||||
success: function (res: wx.RequestSuccessCallbackResult) {
|
||||
responseHandler(res, obj, 'request')
|
||||
},
|
||||
fail: function (res) {
|
||||
fail: function (res: wx.GeneralCallbackResult) {
|
||||
errorHandler(obj, res);
|
||||
console.error(res);
|
||||
},
|
||||
@@ -116,19 +118,18 @@ function doRequest(obj) {
|
||||
})
|
||||
}
|
||||
|
||||
function doUploadFile(obj) {
|
||||
function doUploadFile(obj: TODO) {
|
||||
obj = initialize(obj, 'formData');
|
||||
obj.count++;
|
||||
wx.uploadFile({
|
||||
url: obj.url,
|
||||
filePath: obj.filePath || '',
|
||||
name: obj.name || '',
|
||||
method: 'POST',
|
||||
formData: obj.formData,
|
||||
success: function (res) {
|
||||
success: function (res: wx.UploadFileSuccessCallbackResult) {
|
||||
responseHandler(res, obj, 'uploadFile')
|
||||
},
|
||||
fail: function (res) {
|
||||
fail: function (res: wx.GeneralCallbackResult) {
|
||||
errorHandler(obj, res);
|
||||
console.error(res);
|
||||
},
|
||||
@@ -139,32 +140,32 @@ function doUploadFile(obj) {
|
||||
})
|
||||
}
|
||||
|
||||
function request(obj) {
|
||||
function request(obj: TODO): TODO {
|
||||
obj = preDo(obj);
|
||||
if (config.mockJson) {
|
||||
if(config.mockJson) {
|
||||
mockManager.get(obj, 'request');
|
||||
return false;
|
||||
}
|
||||
if (obj.cache) {
|
||||
if(obj.cache) {
|
||||
cacheManager.get(obj);
|
||||
}
|
||||
|
||||
sessionManager(() => {
|
||||
sessionManager(()=>{
|
||||
doRequest(obj)
|
||||
}, obj)
|
||||
}
|
||||
|
||||
function uploadFile(obj) {
|
||||
function uploadFile(obj: TODO): TODO {
|
||||
obj = preDo(obj);
|
||||
if (config.mockJson) {
|
||||
if(config.mockJson) {
|
||||
mockManager.get(obj, 'uploadFile');
|
||||
return false;
|
||||
}
|
||||
if (obj.cache) {
|
||||
if(obj.cache) {
|
||||
cacheManager.get(obj);
|
||||
}
|
||||
|
||||
sessionManager(() => {
|
||||
sessionManager(()=>{
|
||||
doUploadFile(obj)
|
||||
}, obj)
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import errorHandler from './errorHandler'
|
||||
import cacheManager from './cacheManager'
|
||||
import durationReporter from './durationReporter'
|
||||
|
||||
function response(res, obj, method) {
|
||||
function response(res: wx.RequestSuccessCallbackResult | wx.UploadFileSuccessCallbackResult, obj: TODO, method: "request" | "uploadFile"): any {
|
||||
if (res.statusCode === 200) {
|
||||
|
||||
// 兼容uploadFile返回的res.data可能是字符串
|
||||
@@ -24,7 +24,7 @@ function response(res, obj, method) {
|
||||
// 登录请求
|
||||
let s = "";
|
||||
try {
|
||||
s = config.codeToSession.success(res.data);
|
||||
s = config.codeToSession.success!(res.data);
|
||||
} catch (e) {
|
||||
}
|
||||
if (s) {
|
||||
@@ -32,21 +32,21 @@ function response(res, obj, method) {
|
||||
} else {
|
||||
errorHandler(obj, res);
|
||||
}
|
||||
} else if (config.loginTrigger(res.data) && obj.reLoginLimit < config.reLoginLimit) {
|
||||
} else if (config.loginTrigger!(res.data) && obj.reLoginLimit < config.reLoginLimit!) {
|
||||
// 登录态失效,且重试次数不超过配置
|
||||
status.session = '';
|
||||
status.sessionIsFresh = true;
|
||||
wx.removeStorage({
|
||||
key: config.sessionName,
|
||||
key: config.sessionName!,
|
||||
complete: function () {
|
||||
requestHandler[method](obj)
|
||||
}
|
||||
})
|
||||
} else if (config.successTrigger(res.data)) {
|
||||
} else if (config.successTrigger!(res.data)) {
|
||||
// 接口返回成功码
|
||||
let realData = null;
|
||||
try {
|
||||
realData = config.successData(res.data);
|
||||
realData = config.successData!(res.data);
|
||||
} catch (e) {
|
||||
console.error("Function successData occur error: " + e);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import requestHandler from './requestHandler'
|
||||
import errorHandler from './errorHandler'
|
||||
import durationReporter from './durationReporter'
|
||||
|
||||
function checkSession(callback, obj) {
|
||||
function checkSession(callback: Function, obj: TODO) {
|
||||
if (status.isCheckingSession) {
|
||||
flow.wait('checkSessionFinished', () => {
|
||||
checkSession(callback, obj)
|
||||
@@ -38,7 +38,7 @@ function checkSession(callback, obj) {
|
||||
}
|
||||
}
|
||||
|
||||
function doLogin(callback, obj) {
|
||||
function doLogin(callback: Function, obj: TODO) {
|
||||
if (obj.isLogin) {
|
||||
// 登录接口,直接放过
|
||||
typeof callback === "function" && callback();
|
||||
@@ -90,7 +90,7 @@ function doLogin(callback, obj) {
|
||||
}
|
||||
}
|
||||
|
||||
function code2Session(obj, code, callback) {
|
||||
function code2Session(obj: TODO, code: TODO, callback: Function) {
|
||||
let data;
|
||||
// codeToSession.data支持函数
|
||||
if (typeof config.codeToSession.data === "function") {
|
||||
@@ -98,7 +98,7 @@ function code2Session(obj, code, callback) {
|
||||
} else {
|
||||
data = config.codeToSession.data || {};
|
||||
}
|
||||
data[config.codeToSession.codeName] = code;
|
||||
data[config.codeToSession.codeName!] = code;
|
||||
|
||||
obj.count++;
|
||||
requestHandler.request({
|
||||
@@ -107,7 +107,7 @@ function code2Session(obj, code, callback) {
|
||||
method: config.codeToSession.method || 'GET',
|
||||
isLogin: true,
|
||||
report: config.codeToSession.report || config.codeToSession.url,
|
||||
success: function (s) {
|
||||
success: function (s: TODO) {
|
||||
status.session = s;
|
||||
status.sessionIsFresh = true;
|
||||
// 如果有设置本地session过期时间
|
||||
@@ -115,12 +115,12 @@ function code2Session(obj, code, callback) {
|
||||
status.sessionExpire = new Date().getTime() + status.sessionExpireTime;
|
||||
wx.setStorage({
|
||||
key: config.sessionExpireKey,
|
||||
data: status.sessionExpire
|
||||
data: String(status.sessionExpire)
|
||||
})
|
||||
}
|
||||
typeof callback === "function" && callback();
|
||||
wx.setStorage({
|
||||
key: config.sessionName,
|
||||
key: config.sessionName!,
|
||||
data: status.session
|
||||
})
|
||||
},
|
||||
@@ -1,4 +1,5 @@
|
||||
export default {
|
||||
import { IInitOption } from '../api/init';
|
||||
const defaultConfig: IInitOption = {
|
||||
sessionName: "session",
|
||||
loginTrigger() {
|
||||
return false
|
||||
@@ -8,12 +9,12 @@ export default {
|
||||
return true
|
||||
},
|
||||
urlPerfix: "",
|
||||
successData(res) {
|
||||
successData(res: any) {
|
||||
return res
|
||||
},
|
||||
doNotCheckSession: false,
|
||||
errorTitle: "操作失败",
|
||||
errorContent(res) {
|
||||
errorContent(res: any) {
|
||||
return res
|
||||
},
|
||||
reLoginLimit: 3,
|
||||
@@ -24,3 +25,5 @@ export default {
|
||||
// session在本地缓存的key
|
||||
sessionExpireKey: "sessionExpireKey"
|
||||
}
|
||||
|
||||
export default defaultConfig;
|
||||
@@ -1,12 +1,12 @@
|
||||
export default {
|
||||
session: '',
|
||||
session: '' as string,
|
||||
// session在本地缓存的有效时间
|
||||
sessionExpireTime: null,
|
||||
// session过期的时间点
|
||||
sessionExpire: Infinity,
|
||||
sessionIsFresh: false,
|
||||
sessionIsFresh: false as boolean,
|
||||
// 正在登录中,其他请求轮询稍后,避免重复调用登录接口
|
||||
logining: false,
|
||||
logining: false as boolean,
|
||||
// 正在查询session有效期中,避免重复调用接口
|
||||
isCheckingSession: false
|
||||
}
|
||||
isCheckingSession: false as boolean
|
||||
} as any
|
||||
12
src/typings/index.d.ts
vendored
Normal file
12
src/typings/index.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
***************************************************************************** */
|
||||
|
||||
/// <reference path="./lib.wa.es6.d.ts" />
|
||||
/// <reference path="./wx/index.d.ts" />
|
||||
5819
src/typings/lib.wa.es6.d.ts
vendored
Normal file
5819
src/typings/lib.wa.es6.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
63
src/typings/wx/index.d.ts
vendored
Normal file
63
src/typings/wx/index.d.ts
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
***************************************************************************** */
|
||||
|
||||
/// <reference path="./lib.wx.app.d.ts" />
|
||||
/// <reference path="./lib.wx.page.d.ts" />
|
||||
/// <reference path="./lib.wx.api.d.ts" />
|
||||
/// <reference path="./lib.wx.cloud.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>>;
|
||||
|
||||
/**
|
||||
* Make all properties in T required
|
||||
*/
|
||||
// type Required<T> = {
|
||||
// [P in keyof T]-?: T[P];
|
||||
// };
|
||||
|
||||
/**
|
||||
* Exclude from T those types that are assignable to U
|
||||
*/
|
||||
// type Exclude<T, U> = T extends U ? never : T;
|
||||
|
||||
/**
|
||||
* Extract from T those types that are assignable to U
|
||||
*/
|
||||
// type Extract<T, U> = T extends U ? T : never;
|
||||
|
||||
/**
|
||||
* Exclude null and undefined from T
|
||||
*/
|
||||
// type NonNullable<T> = T extends null | undefined ? never : T;
|
||||
|
||||
/**
|
||||
* Obtain the return type of a function type
|
||||
*/
|
||||
// type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : any;
|
||||
|
||||
/**
|
||||
* Obtain the return type of a constructor function type
|
||||
*/
|
||||
// type InstanceType<T extends new (...args: any[]) => any> = T extends new (...args: any[]) => infer R ? R : any;
|
||||
|
||||
type Optional<T> = { [K in keyof T]+?: T[K] };
|
||||
|
||||
// 临时解决ts,后续小程序工具会更新
|
||||
declare function Component(...args: any[]): any;
|
||||
declare function requirePlugin(pluginName: string): any;
|
||||
declare function require(pluginName: string): any;
|
||||
type TODO = any;
|
||||
12396
src/typings/wx/lib.wx.api.d.ts
vendored
Normal file
12396
src/typings/wx/lib.wx.api.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
250
src/typings/wx/lib.wx.app.d.ts
vendored
Normal file
250
src/typings/wx/lib.wx.app.d.ts
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
declare namespace App {
|
||||
interface ILaunchOptions {
|
||||
query: number
|
||||
}
|
||||
|
||||
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
|
||||
| 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 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 IPageNotFoundOption {
|
||||
/** 不存在页面的路径 */
|
||||
path: string
|
||||
/** 打开不存在页面的 query */
|
||||
query: IAnyObject
|
||||
/** 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */
|
||||
isEntryPage: boolean
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
interface AppConstructor {
|
||||
<T extends IAnyObject & AppInstance>(
|
||||
options: AppInstance<T> & T
|
||||
): void
|
||||
}
|
||||
|
||||
interface IGetAppOption {
|
||||
/** 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包
|
||||
*
|
||||
* 最低基础库: 2.2.4
|
||||
*/
|
||||
allowDefault: boolean
|
||||
}
|
||||
|
||||
interface GetApp {
|
||||
<T extends IAnyObject>(opts?: IGetAppOption): AppInstance<T> & T
|
||||
}
|
||||
}
|
||||
|
||||
declare const App: App.AppConstructor
|
||||
declare const getApp: App.GetApp
|
||||
687
src/typings/wx/lib.wx.cloud.d.ts
vendored
Normal file
687
src/typings/wx/lib.wx.cloud.d.ts
vendored
Normal file
@@ -0,0 +1,687 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
***************************************************************************** */
|
||||
|
||||
/////////////////////
|
||||
///// WX Cloud Apis
|
||||
/////////////////////
|
||||
|
||||
/**
|
||||
* Common interfaces and types
|
||||
*/
|
||||
|
||||
interface IAPIError {
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
interface IAPIParam<T = any> {
|
||||
config?: ICloudConfig,
|
||||
success?: (res: T) => void,
|
||||
fail?: (err: IAPIError) => void,
|
||||
complete?: (val: T | IAPIError) => void,
|
||||
}
|
||||
|
||||
interface IAPISuccessParam {
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
type IAPICompleteParam = IAPISuccessParam | IAPIError
|
||||
|
||||
type IAPIFunction<T, P extends IAPIParam<T>> = (param: P) => Promise<T> | any
|
||||
|
||||
interface IInitCloudConfig {
|
||||
env?: string | {
|
||||
database?: string,
|
||||
functions?: string,
|
||||
storage?: string,
|
||||
},
|
||||
traceUser?: boolean,
|
||||
}
|
||||
|
||||
interface ICloudConfig {
|
||||
env?: string,
|
||||
traceUser?: boolean,
|
||||
}
|
||||
|
||||
interface IICloudAPI {
|
||||
init: (config?: IInitCloudConfig) => void,
|
||||
[api: string]: AnyFunction | IAPIFunction<any, any>,
|
||||
}
|
||||
|
||||
interface ICloudService {
|
||||
name: string,
|
||||
|
||||
getAPIs: () => { [name: string]: IAPIFunction<any, any> },
|
||||
}
|
||||
|
||||
interface ICloudServices {
|
||||
[serviceName: string]: ICloudService
|
||||
}
|
||||
|
||||
interface ICloudMetaData {
|
||||
session_id: string,
|
||||
}
|
||||
|
||||
declare class InternalSymbol {
|
||||
|
||||
}
|
||||
|
||||
type AnyObject = {
|
||||
[x: string]: any
|
||||
}
|
||||
|
||||
type AnyArray = 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,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
declare namespace wx {
|
||||
interface WX {
|
||||
cloud: {
|
||||
init: (config?: ICloudConfig) => void,
|
||||
|
||||
// callFunction: (param: ICloud.CallFunctionParam) => Promise<ICloud.CallFunctionResult> | void,
|
||||
|
||||
// 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,
|
||||
|
||||
callFunction(param: OQ<ICloud.CallFunctionParam>): void
|
||||
callFunction(param: RQ<ICloud.CallFunctionParam>): Promise<ICloud.CallFunctionResult>
|
||||
|
||||
uploadFile(param: OQ<ICloud.UploadFileParam>): WXNS.IUploadFileTask
|
||||
uploadFile(param: RQ<ICloud.UploadFileParam>): Promise<ICloud.UploadFileResult>
|
||||
|
||||
downloadFile(param: OQ<ICloud.DownloadFileParam>): WXNS.IDownloadFileTask
|
||||
downloadFile(param: RQ<ICloud.DownloadFileParam>): Promise<ICloud.DownloadFileResult>
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace ICloud {
|
||||
|
||||
interface ICloudAPIParam<T = any> extends IAPIParam<T> {
|
||||
config?: ICloudConfig
|
||||
}
|
||||
|
||||
// === API: callFunction ===
|
||||
export type CallFunctionData = AnyObject
|
||||
|
||||
export interface CallFunctionResult extends IAPISuccessParam {
|
||||
result: AnyObject | string | undefined,
|
||||
}
|
||||
|
||||
export interface CallFunctionParam extends ICloudAPIParam<CallFunctionResult> {
|
||||
name: string,
|
||||
data?: CallFunctionData,
|
||||
slow?: boolean,
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: uploadFile ===
|
||||
export interface UploadFileResult extends IAPISuccessParam {
|
||||
fileID: string,
|
||||
statusCode: number,
|
||||
}
|
||||
|
||||
export interface UploadFileParam extends ICloudAPIParam<UploadFileResult> {
|
||||
cloudPath: string,
|
||||
filePath: string,
|
||||
header?: AnyObject,
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: downloadFile ===
|
||||
export interface DownloadFileResult extends IAPISuccessParam {
|
||||
tempFilePath: string,
|
||||
statusCode: number,
|
||||
}
|
||||
|
||||
export interface DownloadFileParam extends ICloudAPIParam<DownloadFileResult> {
|
||||
fileID: string,
|
||||
cloudPath?: string,
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: getTempFileURL ===
|
||||
export interface GetTempFileURLResult extends IAPISuccessParam {
|
||||
fileList: GetTempFileURLResultItem[],
|
||||
}
|
||||
|
||||
export interface GetTempFileURLResultItem {
|
||||
fileID: string,
|
||||
tempFileURL: string,
|
||||
maxAge: number,
|
||||
status: number,
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
export interface GetTempFileURLParam extends ICloudAPIParam<GetTempFileURLResult> {
|
||||
fileList: string[],
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: deleteFile ===
|
||||
interface DeleteFileResult extends IAPISuccessParam {
|
||||
fileList: DeleteFileResultItem[],
|
||||
}
|
||||
|
||||
interface DeleteFileResultItem {
|
||||
fileID: string,
|
||||
status: number,
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
interface DeleteFileParam extends ICloudAPIParam<DeleteFileResult> {
|
||||
fileList: string[],
|
||||
}
|
||||
// === end ===
|
||||
|
||||
}
|
||||
|
||||
// === Database ===
|
||||
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: Geo
|
||||
public readonly serverDate: () => ServerDate
|
||||
|
||||
private constructor();
|
||||
|
||||
collection(collectionName: string): CollectionReference
|
||||
|
||||
}
|
||||
|
||||
export class CollectionReference extends Query {
|
||||
|
||||
public readonly collectionName: string
|
||||
public readonly database: Database
|
||||
|
||||
private constructor(name: string, database: Database)
|
||||
|
||||
doc(docId: string | number): DocumentReference
|
||||
|
||||
// add(options: IAddDocumentOptions): Promise<IAddResult> | void
|
||||
|
||||
add(options: OQ<IAddDocumentOptions>): void
|
||||
add(options: RQ<IAddDocumentOptions>): Promise<IAddResult>
|
||||
|
||||
}
|
||||
|
||||
export class DocumentReference {
|
||||
|
||||
private constructor(docId: string | number, database: Database)
|
||||
|
||||
field(object: object): this
|
||||
|
||||
// get(options?: IGetDocumentOptions): Promise<IQuerySingleResult> | void
|
||||
|
||||
// set(options?: ISetSingleDocumentOptions): Promise<ISetResult> | void
|
||||
|
||||
// update(options?: IUpdateSingleDocumentOptions): Promise<IUpdateResult> | void
|
||||
|
||||
// remove(options?: IRemoveSingleDocumentOptions): Promise<IRemoveResult> | void
|
||||
|
||||
// get(options?: IGetDocumentOptions): Promise<IQuerySingleResult> | void
|
||||
get(): Promise<IQuerySingleResult>
|
||||
get(options: OQ<IGetDocumentOptions>): void
|
||||
get(options: RQ<IGetDocumentOptions>): Promise<IQuerySingleResult>
|
||||
|
||||
// set(options?: ISetSingleDocumentOptions): Promise<ISetResult> | void
|
||||
set(): Promise<ISetResult>
|
||||
set(options: OQ<ISetSingleDocumentOptions>): void
|
||||
set(options: RQ<ISetSingleDocumentOptions>): Promise<ISetResult>
|
||||
|
||||
// update(options?: IUpdateSingleDocumentOptions): Promise<IUpdateResult> | void
|
||||
update(): Promise<IUpdateResult>
|
||||
update(options: OQ<IUpdateSingleDocumentOptions>): void
|
||||
update(options: RQ<IUpdateSingleDocumentOptions>): Promise<IUpdateResult>
|
||||
|
||||
// remove(options?: IRemoveSingleDocumentOptions): Promise<IRemoveResult> | void
|
||||
remove(): Promise<IRemoveResult>
|
||||
remove(options: OQ<IRemoveSingleDocumentOptions>): void
|
||||
remove(options: RQ<IRemoveSingleDocumentOptions>): Promise<IRemoveResult>
|
||||
|
||||
}
|
||||
|
||||
export class Query {
|
||||
|
||||
where(condition: IQueryCondition): Query
|
||||
|
||||
orderBy(fieldPath: string, order: string): Query
|
||||
|
||||
limit(max: number): Query
|
||||
|
||||
skip(offset: number): Query
|
||||
|
||||
field(object: object): Query
|
||||
|
||||
// get(options?: IGetDocumentOptions): Promise<IQueryResult> | void
|
||||
|
||||
// // update(options?: IUpdateDocumentOptions): Promise<IUpdateResult> | void
|
||||
|
||||
// // remove(options?: IRemoveDocumentOptions): Promise<IRemoveResult> | void
|
||||
|
||||
// count(options?: ICountDocumentOptions): Promise<ICountResult> | void
|
||||
|
||||
// get(options?: IGetDocumentOptions): Promise<IQueryResult> | void
|
||||
get(): Promise<IQueryResult>
|
||||
get(options: OQ<IGetDocumentOptions>): void
|
||||
get(options: RQ<IGetDocumentOptions>): Promise<IQueryResult>
|
||||
|
||||
// update(options?: IUpdateDocumentOptions): Promise<IUpdateResult> | void
|
||||
|
||||
// remove(options?: IRemoveDocumentOptions): Promise<IRemoveResult> | void
|
||||
|
||||
// count(options?: ICountDocumentOptions): Promise<ICountResult> | void
|
||||
count(): Promise<ICountResult>
|
||||
count(options: OQ<ICountDocumentOptions>): void
|
||||
count(options: RQ<ICountDocumentOptions>): Promise<ICountResult>
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
and(...expressions: (DatabaseLogicCommand | IQueryCondition)[]): DatabaseLogicCommand
|
||||
or(...expressions: (DatabaseLogicCommand | IQueryCondition)[]): DatabaseLogicCommand
|
||||
|
||||
set(val: any): DatabaseUpdateCommand
|
||||
remove(): DatabaseUpdateCommand
|
||||
inc(val: number): DatabaseUpdateCommand
|
||||
mul(val: number): DatabaseUpdateCommand
|
||||
|
||||
push(...values: any[]): DatabaseUpdateCommand
|
||||
pop(): DatabaseUpdateCommand
|
||||
shift(): DatabaseUpdateCommand
|
||||
unshift(...values: any[]): DatabaseUpdateCommand
|
||||
|
||||
}
|
||||
|
||||
export enum LOGIC_COMMANDS_LITERAL {
|
||||
AND = 'and',
|
||||
OR = 'or',
|
||||
NOT = 'not',
|
||||
NOR = 'nor',
|
||||
}
|
||||
|
||||
export class DatabaseLogicCommand {
|
||||
|
||||
public fieldName: string | InternalSymbol
|
||||
public operator: LOGIC_COMMANDS_LITERAL | string
|
||||
public operands: any[]
|
||||
|
||||
_setFieldName(fieldName: string): DatabaseLogicCommand
|
||||
|
||||
and(...expressions: (DatabaseLogicCommand | IQueryCondition)[]): DatabaseLogicCommand
|
||||
or(...expressions: (DatabaseLogicCommand | IQueryCondition)[]): DatabaseLogicCommand
|
||||
|
||||
}
|
||||
|
||||
export enum QUERY_COMMANDS_LITERAL {
|
||||
EQ = 'eq',
|
||||
NEQ = 'neq',
|
||||
GT = 'gt',
|
||||
GTE = 'gte',
|
||||
LT = 'lt',
|
||||
LTE = 'lte',
|
||||
IN = 'in',
|
||||
NIN = 'nin',
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
getCallbackReturn(param: PARAM, context: CONTEXT): CALLBACK_RETURN
|
||||
|
||||
getFinalParam<T extends PARAM>(param: PARAM, context: CONTEXT): T
|
||||
|
||||
run<T extends PARAM>(param: T): Promise<PROMISE_RETURN>
|
||||
|
||||
}
|
||||
|
||||
export interface GeoPointConstructor {
|
||||
new (longitude: number, latitide: number): GeoPoint
|
||||
}
|
||||
|
||||
export interface Geo {
|
||||
Point: {
|
||||
new (longitude: number, latitide: number): GeoPoint
|
||||
(longitude: number, latitide: number): GeoPoint
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class GeoPoint {
|
||||
public longitude: number
|
||||
public latitude: number
|
||||
|
||||
constructor(longitude: number, latitude: number)
|
||||
|
||||
toJSON(): object
|
||||
toString(): string
|
||||
}
|
||||
|
||||
export interface IServerDateOptions {
|
||||
offset: number,
|
||||
}
|
||||
|
||||
export abstract class ServerDate {
|
||||
public readonly options: IServerDateOptions
|
||||
constructor(options?: IServerDateOptions)
|
||||
}
|
||||
|
||||
export type DocumentId = string | number
|
||||
|
||||
export interface IDocumentData {
|
||||
_id?: DocumentId,
|
||||
[key: string]: any,
|
||||
}
|
||||
|
||||
export interface IDBAPIParam extends IAPIParam {
|
||||
|
||||
}
|
||||
|
||||
export interface IAddDocumentOptions extends IDBAPIParam {
|
||||
data: IDocumentData,
|
||||
}
|
||||
|
||||
export interface IGetDocumentOptions extends IDBAPIParam {
|
||||
|
||||
}
|
||||
|
||||
export interface ICountDocumentOptions extends IDBAPIParam {
|
||||
|
||||
}
|
||||
|
||||
export interface IUpdateDocumentOptions extends IDBAPIParam {
|
||||
data: IUpdateCondition,
|
||||
}
|
||||
|
||||
export interface IUpdateSingleDocumentOptions extends IDBAPIParam {
|
||||
data: IUpdateCondition,
|
||||
}
|
||||
|
||||
export interface ISetDocumentOptions extends IDBAPIParam {
|
||||
data: IUpdateCondition,
|
||||
}
|
||||
|
||||
export interface ISetSingleDocumentOptions extends IDBAPIParam {
|
||||
data: IUpdateCondition,
|
||||
}
|
||||
|
||||
export interface IRemoveDocumentOptions extends IDBAPIParam {
|
||||
query: IQueryCondition,
|
||||
}
|
||||
|
||||
export interface IRemoveSingleDocumentOptions extends IDBAPIParam {
|
||||
|
||||
}
|
||||
|
||||
export interface IQueryCondition {
|
||||
[key: string]: any,
|
||||
}
|
||||
|
||||
export type IStringQueryCondition = string
|
||||
|
||||
export interface IQueryResult extends IAPISuccessParam {
|
||||
data: IDocumentData[],
|
||||
}
|
||||
|
||||
export interface IQuerySingleResult extends IAPISuccessParam {
|
||||
data: IDocumentData,
|
||||
}
|
||||
|
||||
export interface IUpdateCondition {
|
||||
[key: string]: any,
|
||||
}
|
||||
|
||||
export type IStringUpdateCondition = string
|
||||
|
||||
export interface ISetCondition {
|
||||
|
||||
}
|
||||
|
||||
export interface IAddResult extends IAPISuccessParam {
|
||||
_id: DocumentId,
|
||||
}
|
||||
|
||||
export interface IUpdateResult extends IAPISuccessParam {
|
||||
stats: {
|
||||
updated: number,
|
||||
// created: number,
|
||||
}
|
||||
}
|
||||
|
||||
export interface ISetResult extends IAPISuccessParam {
|
||||
_id: DocumentId,
|
||||
stats: {
|
||||
updated: number,
|
||||
created: number,
|
||||
}
|
||||
}
|
||||
|
||||
export interface IRemoveResult extends IAPISuccessParam {
|
||||
stats: {
|
||||
removed: number,
|
||||
}
|
||||
}
|
||||
|
||||
export interface ICountResult extends IAPISuccessParam {
|
||||
total: number
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Utils
|
||||
*/
|
||||
|
||||
type OQ<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'>>)
|
||||
|
||||
type RQ<T extends Optional<Record<'complete' | 'success' | 'fail', (...args: any[]) => any>>> = Pick<T, Exclude<keyof T, 'complete' | 'success' | 'fail'>>
|
||||
|
||||
181
src/typings/wx/lib.wx.page.d.ts
vendored
Normal file
181
src/typings/wx/lib.wx.page.d.ts
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace Page {
|
||||
|
||||
interface ICustomShareContent {
|
||||
/** 转发标题。默认值:当前小程序名称 */
|
||||
title?: string
|
||||
/** 转发路径,必须是以 / 开头的完整路径。默认值:当前页面 path */
|
||||
path?: string
|
||||
/** 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持PNG及JPG。显示图片长宽比是 5:4,最低基础库: `1.5.0`。默认值:使用默认截图 */
|
||||
imageUrl?: string
|
||||
}
|
||||
|
||||
interface IPageScrollOption {
|
||||
/** 页面在垂直方向已滚动的距离(单位px) */
|
||||
scrollTop: number
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
interface ITabItemTapOption {
|
||||
/** 被点击tabItem的序号,从0开始,最低基础库: `1.9.0` */
|
||||
index: string
|
||||
/** 被点击tabItem的页面路径,最低基础库: `1.9.0` */
|
||||
pagePath: string
|
||||
/** 被点击tabItem的按钮文字,最低基础库: `1.9.0` */
|
||||
text: string
|
||||
}
|
||||
|
||||
interface PageInstanceBaseProps<D extends IAnyObject = any> {
|
||||
/** 页面的初始数据
|
||||
*
|
||||
* `data` 是页面第一次渲染使用的**初始数据**。
|
||||
*
|
||||
* 页面加载时,`data` 将会以`JSON`字符串的形式由逻辑层传至渲染层,因此`data`中的数据必须是可以转成`JSON`的类型:字符串,数字,布尔值,对象,数组。
|
||||
*
|
||||
* 渲染层可以通过 `WXML` 对数据进行绑定。
|
||||
*/
|
||||
data?: D
|
||||
|
||||
/** `setData` 函数用于将数据从逻辑层发送到视图层(异步),同时改变对应的 `this.data` 的值(同步)。
|
||||
*
|
||||
* **注意:**
|
||||
*
|
||||
* 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。
|
||||
* 1. 仅支持设置可 JSON 化的数据。
|
||||
* 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。
|
||||
* 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。
|
||||
*/
|
||||
|
||||
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
|
||||
|
||||
/** 到当前页面的路径,类型为`String`。最低基础库: `1.2.0` */
|
||||
route?: string
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
/** 当前是 tab 页时,点击 tab 时触发,最低基础库: `1.9.0` */
|
||||
onTabItemTap?(
|
||||
/** tab 点击参数 */
|
||||
options?: ITabItemTapOption
|
||||
): 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
|
||||
@@ -1,6 +1,6 @@
|
||||
let store = {};
|
||||
let store: TODO = {};
|
||||
|
||||
function emit(key) {
|
||||
function emit(key: TODO) {
|
||||
let flow = getFlow(key);
|
||||
let currentLength = flow.waitingList.length;
|
||||
for (let i = 0; i < currentLength; i++) {
|
||||
@@ -9,12 +9,12 @@ function emit(key) {
|
||||
}
|
||||
}
|
||||
|
||||
function wait(key, callback) {
|
||||
function wait(key: TODO, callback: Function) {
|
||||
var flow = getFlow(key);
|
||||
flow.waitingList.push(callback)
|
||||
}
|
||||
|
||||
function getFlow(key) {
|
||||
function getFlow(key: TODO) {
|
||||
if (!store[key]) {
|
||||
store[key] = {
|
||||
waitingList: []
|
||||
@@ -1,4 +1,4 @@
|
||||
function show(txt) {
|
||||
function show(txt: boolean | string) {
|
||||
wx.showToast({
|
||||
title: typeof txt === 'boolean' ? '加载中' : txt,
|
||||
icon: 'loading',
|
||||
@@ -8,7 +8,7 @@ function show(txt) {
|
||||
}
|
||||
|
||||
function hide() {
|
||||
wx.hideToast();
|
||||
wx.hideToast({});
|
||||
}
|
||||
|
||||
export default {
|
||||
28
src/util/url.ts
Normal file
28
src/util/url.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
function setParams(url: string, params: object) {
|
||||
let queryStringIndex = url.indexOf('?');
|
||||
let kvp: any = {};
|
||||
if (queryStringIndex >= 0) {
|
||||
let oldQueryString = url.substr(queryStringIndex + 1).split('&');
|
||||
for (let i = 0; i < oldQueryString.length; i++) {
|
||||
let kv = oldQueryString[i].split('=');
|
||||
kvp[kv[0]] = kv[1]
|
||||
}
|
||||
}
|
||||
|
||||
kvp = {...kvp, ...params};
|
||||
|
||||
let queryString = Object.keys(kvp).map(key => {
|
||||
return `${key}=${encodeURI(kvp[key])}`
|
||||
}).join('&');
|
||||
|
||||
if (queryStringIndex >= 0) {
|
||||
return url.substring(0, queryStringIndex + 1) + queryString
|
||||
} else {
|
||||
return url + "?" + queryString
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
setParams
|
||||
}
|
||||
29
tsconfig.json
Normal file
29
tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./build/",
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": true,
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "node",
|
||||
"target": "ES5",
|
||||
"allowJs": false,
|
||||
"experimentalDecorators": true,
|
||||
"noImplicitThis": true,
|
||||
"noImplicitReturns": true,
|
||||
"alwaysStrict": true,
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"strict": true,
|
||||
"removeComments": true,
|
||||
"pretty": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"typeRoots": ["./src/typings"],
|
||||
"lib": ["es5", "es2015", "dom", "scripthost"],
|
||||
"declaration": true
|
||||
},
|
||||
"include": ["./src/**/*.ts"],
|
||||
"exclude": ["node_modules", "build", "**/*.spec.ts", "**/*.d.ts"]
|
||||
}
|
||||
17
tslint.json
Normal file
17
tslint.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"jsRules": {},
|
||||
"rules": {
|
||||
"object-literal-sort-keys": false,
|
||||
"no-empty": false,
|
||||
"no-string-literal": false,
|
||||
"ordered-imports": false,
|
||||
"no-empty-interface": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"no-var-requires": false,
|
||||
"no-console": false,
|
||||
"no-object-literal-type-assertion": false
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
||||
@@ -1,34 +1,61 @@
|
||||
let path = require('path');
|
||||
let webpack = require('webpack');
|
||||
let pk = require('./package.json');
|
||||
let path = require("path");
|
||||
let webpack = require("webpack");
|
||||
let pk = require("./package.json");
|
||||
|
||||
module.exports = [{
|
||||
mode: 'production',
|
||||
entry: './src/index.js',
|
||||
module.exports = [
|
||||
{
|
||||
mode: "production",
|
||||
entry: "./src/index.ts",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
use: "ts-loader",
|
||||
exclude: /node_modules/
|
||||
}
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".tsx", ".ts", ".js"]
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, 'build'),
|
||||
filename: 'weRequest.min.js',
|
||||
library: "weRequest",
|
||||
libraryTarget: "commonjs-module"
|
||||
path: path.join(__dirname, "build"),
|
||||
filename: "weRequest.min.js",
|
||||
library: "weRequest",
|
||||
libraryTarget: "commonjs-module"
|
||||
},
|
||||
plugins: [
|
||||
new webpack.BannerPlugin({
|
||||
banner: `weRequest ${pk.version}\n${pk.homepage}`
|
||||
})
|
||||
new webpack.BannerPlugin({
|
||||
banner: `weRequest ${pk.version}\n${pk.homepage}`
|
||||
})
|
||||
]
|
||||
}, {
|
||||
mode: 'development',
|
||||
entry: './src/index.js',
|
||||
output: {
|
||||
path: path.join(__dirname, 'build'),
|
||||
filename: 'weRequest.js',
|
||||
library: "weRequest",
|
||||
libraryTarget: "commonjs-module"
|
||||
},
|
||||
{
|
||||
mode: "development",
|
||||
entry: "./src/index.ts",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
use: "ts-loader",
|
||||
exclude: /node_modules/
|
||||
}
|
||||
]
|
||||
},
|
||||
devtool: 'inline-source-map',
|
||||
resolve: {
|
||||
extensions: [".tsx", ".ts", ".js"]
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, "build"),
|
||||
filename: "weRequest.js",
|
||||
library: "weRequest",
|
||||
libraryTarget: "commonjs-module"
|
||||
},
|
||||
devtool: "inline-source-map",
|
||||
plugins: [
|
||||
new webpack.BannerPlugin({
|
||||
banner: `weRequest ${pk.version}\n${pk.homepage}`
|
||||
})
|
||||
new webpack.BannerPlugin({
|
||||
banner: `weRequest ${pk.version}\n${pk.homepage}`
|
||||
})
|
||||
]
|
||||
}]
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user