@mptool/all 0.6.0-beta.9 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.mts CHANGED
@@ -1,6 +1,103 @@
1
1
  declare const encode: (arraybuffer: ArrayBuffer) => string;
2
2
  declare const decode: (base64: string) => ArrayBuffer;
3
3
 
4
+ declare const isQQ: boolean;
5
+ declare const isWx: boolean;
6
+ declare const isMp: boolean;
7
+
8
+ type EventType = string | symbol;
9
+ type Handler<T = unknown> = (event: T) => void | Promise<void>;
10
+ type WildcardHandler<T = Record<string, unknown>> = (type: keyof T, event: T[keyof T]) => void | Promise<void>;
11
+ type EventHandlerList<T = unknown> = Array<Handler<T>>;
12
+ type WildCardEventHandlerList<T = Record<string, unknown>> = Array<WildcardHandler<T>>;
13
+ type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<keyof Events | "*", EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>>;
14
+ interface EmitterInstance<Events extends Record<EventType, unknown>> {
15
+ all: EventHandlerMap<Events>;
16
+ on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;
17
+ on(type: "*", handler: WildcardHandler<Events>): void;
18
+ off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;
19
+ off(type: "*", handler: WildcardHandler<Events>): void;
20
+ emit<Key extends keyof Events>(type: Key, event: Events[Key]): void;
21
+ emit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void;
22
+ emitAsync<Key extends keyof Events>(type: Key, event: Events[Key]): Promise<void>;
23
+ emitAsync<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): Promise<void>;
24
+ }
25
+ /**
26
+ * Tiny (~300b) functional event emitter / pubsub.
27
+ * @name emitter
28
+ * @returns Emitter
29
+ */
30
+ declare function Emitter<Events extends Record<EventType, unknown>>(all?: EventHandlerMap<Events>): EmitterInstance<Events>;
31
+
32
+ /** 写入普通日志 */
33
+ declare const debug: (...args: any[]) => void;
34
+ /** 写入信息日志 */
35
+ declare const info: (...args: any[]) => void;
36
+ /** 写入警告日志 */
37
+ declare const warn: (...args: any[]) => void;
38
+ /** 写入错误日志 */
39
+ declare const error: (...args: any[]) => void;
40
+ /**
41
+ * 写入过滤信息
42
+ *
43
+ * @param filterMsg 过滤信息
44
+ */
45
+ declare const filter: (filterMsg: string) => void;
46
+
47
+ declare const logger_debug: typeof debug;
48
+ declare const logger_error: typeof error;
49
+ declare const logger_filter: typeof filter;
50
+ declare const logger_info: typeof info;
51
+ declare const logger_warn: typeof warn;
52
+ declare namespace logger {
53
+ export { logger_debug as debug, logger_error as error, logger_filter as filter, logger_info as info, logger_warn as warn };
54
+ }
55
+
56
+ /**
57
+ * 字符串参数解析
58
+ *
59
+ * @param queryString 需要解析的字符串
60
+ * @param [splitter='&'] 分隔符
61
+ *
62
+ * @returns 参数对象
63
+ */
64
+ declare const parse: (queryString?: string, splitter?: string) => Record<string, string>;
65
+ /**
66
+ * query 对象转换字符串
67
+ *
68
+ * @param params query 对象
69
+ * @param [splitter='&] 分隔符
70
+ * @param [unencoded=false] 是否已经解码
71
+ *
72
+ * @returns 解析的字符串
73
+ */
74
+ declare const stringify: (params?: Record<string, string>, splitter?: string, unencoded?: boolean) => string;
75
+ /**
76
+ * URL 添加 query
77
+ *
78
+ * @param path 前部分路径
79
+ * @param queries query对象
80
+ * @param unencoded 是否已经解码,默认为否
81
+ *
82
+ * @returns 处理过的 url
83
+ */
84
+ declare const join: (path: string, queries: Record<string, string>, unencoded?: boolean) => string;
85
+
86
+ declare const query_join: typeof join;
87
+ declare const query_parse: typeof parse;
88
+ declare const query_stringify: typeof stringify;
89
+ declare namespace query {
90
+ export { query_join as join, query_parse as parse, query_stringify as stringify };
91
+ }
92
+
93
+ /**
94
+ * 获取变量类型
95
+ *
96
+ * @param obj 需要辨别的变量
97
+ * @returns 对象的类型
98
+ */
99
+ declare const type: (obj: unknown) => string;
100
+
4
101
  /**
5
102
  * 包装函数,先执行 wrapper ,然后执行原函数
6
103
  *
@@ -111,99 +208,6 @@ declare class Queue {
111
208
  */
112
209
  declare const funcQueue: <A extends unknown[], T = unknown>(fn: (next: () => void, ...args: A) => void, capacity?: number) => (this: T, ...args: A) => void;
113
210
 
114
- type EventType = string | symbol;
115
- type Handler<T = unknown> = (event: T) => void | Promise<void>;
116
- type WildcardHandler<T = Record<string, unknown>> = (type: keyof T, event: T[keyof T]) => void | Promise<void>;
117
- type EventHandlerList<T = unknown> = Array<Handler<T>>;
118
- type WildCardEventHandlerList<T = Record<string, unknown>> = Array<WildcardHandler<T>>;
119
- type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<keyof Events | "*", EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>>;
120
- interface EmitterInstance<Events extends Record<EventType, unknown>> {
121
- all: EventHandlerMap<Events>;
122
- on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;
123
- on(type: "*", handler: WildcardHandler<Events>): void;
124
- off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;
125
- off(type: "*", handler: WildcardHandler<Events>): void;
126
- emit<Key extends keyof Events>(type: Key, event: Events[Key]): void;
127
- emit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void;
128
- emitAsync<Key extends keyof Events>(type: Key, event: Events[Key]): Promise<void>;
129
- emitAsync<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): Promise<void>;
130
- }
131
- /**
132
- * Tiny (~300b) functional event emitter / pubsub.
133
- * @name emitter
134
- * @returns Emitter
135
- */
136
- declare function Emitter<Events extends Record<EventType, unknown>>(all?: EventHandlerMap<Events>): EmitterInstance<Events>;
137
-
138
- /** 写入普通日志 */
139
- declare const debug: (...args: any[]) => void;
140
- /** 写入信息日志 */
141
- declare const info: (...args: any[]) => void;
142
- /** 写入警告日志 */
143
- declare const warn: (...args: any[]) => void;
144
- /** 写入错误日志 */
145
- declare const error: (...args: any[]) => void;
146
- /**
147
- * 写入过滤信息
148
- *
149
- * @param filterMsg 过滤信息
150
- */
151
- declare const filter: (filterMsg: string) => void;
152
-
153
- declare const logger_debug: typeof debug;
154
- declare const logger_error: typeof error;
155
- declare const logger_filter: typeof filter;
156
- declare const logger_info: typeof info;
157
- declare const logger_warn: typeof warn;
158
- declare namespace logger {
159
- export { logger_debug as debug, logger_error as error, logger_filter as filter, logger_info as info, logger_warn as warn };
160
- }
161
-
162
- /**
163
- * 字符串参数解析
164
- *
165
- * @param queryString 需要解析的字符串
166
- * @param [splitter='&'] 分隔符
167
- *
168
- * @returns 参数对象
169
- */
170
- declare const parse: (queryString?: string, splitter?: string) => Record<string, string>;
171
- /**
172
- * query 对象转换字符串
173
- *
174
- * @param params query 对象
175
- * @param [splitter='&] 分隔符
176
- * @param [unencoded=false] 是否已经解码
177
- *
178
- * @returns 解析的字符串
179
- */
180
- declare const stringify: (params?: Record<string, string>, splitter?: string, unencoded?: boolean) => string;
181
- /**
182
- * URL 添加 query
183
- *
184
- * @param path 前部分路径
185
- * @param queries query对象
186
- * @param unencoded 是否已经解码,默认为否
187
- *
188
- * @returns 处理过的 url
189
- */
190
- declare const join: (path: string, queries: Record<string, string>, unencoded?: boolean) => string;
191
-
192
- declare const query_join: typeof join;
193
- declare const query_parse: typeof parse;
194
- declare const query_stringify: typeof stringify;
195
- declare namespace query {
196
- export { query_join as join, query_parse as parse, query_stringify as stringify };
197
- }
198
-
199
- /**
200
- * 获取变量类型
201
- *
202
- * @param obj 需要辨别的变量
203
- * @returns 对象的类型
204
- */
205
- declare const type: (obj: unknown) => string;
206
-
207
211
  type Props = Record<string, unknown>;
208
212
  type PropsOptions<Property = Props> = {
209
213
  [K in keyof Property]: PropItem<Property[K]> | null;
@@ -1157,11 +1161,11 @@ interface UrlInfo {
1157
1161
  }
1158
1162
  declare const getDomain: (domainOrURL: string) => string;
1159
1163
  declare const parseUrl: (url: string) => UrlInfo;
1160
- type CookieStoreOptions = string | {
1164
+ type CookieOptions = string | {
1161
1165
  domain?: string;
1162
1166
  path?: string;
1163
1167
  };
1164
- declare const getCookieOptions: (options?: CookieStoreOptions) => UrlInfo;
1168
+ declare const getCookieOptions: (options: CookieOptions) => UrlInfo;
1165
1169
  declare const parseCookieHeader: (setCookieHeader: string, domain: string) => Cookie[];
1166
1170
 
1167
1171
  type CookieMap = Map<string, Cookie>;
@@ -1192,7 +1196,7 @@ declare class CookieStore {
1192
1196
  * @param options Cookie 选项
1193
1197
  * @return cookie 对象
1194
1198
  */
1195
- get(name: string, options: CookieStoreOptions): Cookie | null;
1199
+ get(name: string, options: CookieOptions): Cookie | null;
1196
1200
  /**
1197
1201
  * 获取 Cookie 值
1198
1202
  *
@@ -1200,7 +1204,7 @@ declare class CookieStore {
1200
1204
  * @param options Cookie 选项
1201
1205
  * @return Cookie 值
1202
1206
  */
1203
- getValue(name: string, options: CookieStoreOptions): string | undefined;
1207
+ getValue(name: string, options: CookieOptions): string | undefined;
1204
1208
  /**
1205
1209
  * 是否有特定的 Cookie
1206
1210
  *
@@ -1208,7 +1212,7 @@ declare class CookieStore {
1208
1212
  * @param options Cookie 选项
1209
1213
  * @return 是否存在
1210
1214
  */
1211
- has(name: string, options: CookieStoreOptions): boolean;
1215
+ has(name: string, options: CookieOptions): boolean;
1212
1216
  /**
1213
1217
  * 设置 cookie
1214
1218
  */
@@ -1230,7 +1234,7 @@ declare class CookieStore {
1230
1234
  * @param options Cookie 选项
1231
1235
  * @return Cookie 对象数组
1232
1236
  */
1233
- getCookies(options?: CookieStoreOptions): Cookie[];
1237
+ getCookies(options: CookieOptions): Cookie[];
1234
1238
  /**
1235
1239
  * 获取所有 cookies 对象
1236
1240
  *
@@ -1242,7 +1246,7 @@ declare class CookieStore {
1242
1246
  *
1243
1247
  * @return 键值 Map
1244
1248
  */
1245
- getCookiesMap(options: CookieStoreOptions): Record<string, string>;
1249
+ getCookiesMap(options: CookieOptions): Record<string, string>;
1246
1250
  /**
1247
1251
  * 应用 Cookies
1248
1252
  *
@@ -1261,21 +1265,21 @@ declare class CookieStore {
1261
1265
  * @param header 小程序 response header
1262
1266
  * @param domainOrURL Url 或域名
1263
1267
  */
1264
- applyHeader(header: WechatMiniprogram.IAnyObject, domainOrURL: string): void;
1268
+ applyHeader(header: unknown, domainOrURL: string): void;
1265
1269
  /**
1266
1270
  * 应用响应 cookies
1267
1271
  *
1268
1272
  * @param response 小程序 response
1269
1273
  * @param domainOrURL Url 或域名
1270
1274
  */
1271
- applyResponse(response: WechatMiniprogram.RequestSuccessCallbackResult, domainOrURL: string): void;
1275
+ applyResponse(response: unknown, domainOrURL: string): void;
1272
1276
  /**
1273
1277
  * 获取 request cookie header
1274
1278
  *
1275
1279
  * @param options Cookie 选项
1276
1280
  * @return request cookie header
1277
1281
  */
1278
- getHeader(options: CookieStoreOptions): string;
1282
+ getHeader(options: CookieOptions): string;
1279
1283
  /**
1280
1284
  * 从 Storage 读取 cookies
1281
1285
  */
@@ -1406,9 +1410,9 @@ declare class URLSearchParams {
1406
1410
  [Symbol.iterator](): IterableIterator<[string, string]>;
1407
1411
  }
1408
1412
 
1409
- declare const fetchCookieStore: CookieStore;
1410
- type FetchBody = WechatMiniprogram.IAnyObject | ArrayBuffer | URLSearchParams | string | null;
1411
- interface FetchOptions<T extends Record<never, never> | unknown[] | string | ArrayBuffer = Record<string, any>> extends Omit<WechatMiniprogram.RequestOption<T>, "url" | "method" | "header" | "data"> {
1413
+ declare const requestCookieStore: CookieStore;
1414
+ type RequestBody = WechatMiniprogram.IAnyObject | ArrayBuffer | URLSearchParams | string | null;
1415
+ interface RequestOptions<T extends Record<never, never> | unknown[] | string | ArrayBuffer = Record<string, any>> extends Omit<WechatMiniprogram.RequestOption<T>, "url" | "method" | "header" | "data"> {
1412
1416
  /**
1413
1417
  * 请求方法
1414
1418
  */
@@ -1420,7 +1424,7 @@ interface FetchOptions<T extends Record<never, never> | unknown[] | string | Arr
1420
1424
  /**
1421
1425
  * 请求主体
1422
1426
  */
1423
- body?: FetchBody;
1427
+ body?: RequestBody;
1424
1428
  /**
1425
1429
  * Cookie 作用域
1426
1430
  */
@@ -1430,7 +1434,7 @@ interface FetchOptions<T extends Record<never, never> | unknown[] | string | Arr
1430
1434
  */
1431
1435
  cookieStore?: CookieStore;
1432
1436
  }
1433
- interface FetchResponse<T extends Record<never, never> | unknown[] | string | ArrayBuffer = Record<string, any>> {
1437
+ interface RequestResponse<T extends Record<never, never> | unknown[] | string | ArrayBuffer = Record<string, any>> {
1434
1438
  /** Status Code */
1435
1439
  status: number;
1436
1440
  /** Response headers */
@@ -1438,15 +1442,13 @@ interface FetchResponse<T extends Record<never, never> | unknown[] | string | Ar
1438
1442
  /** Response data */
1439
1443
  data: T;
1440
1444
  }
1441
- type FetchType = <T extends Record<never, never> | unknown[] | string | ArrayBuffer = Record<string, any>>(url: string, options?: FetchOptions<T>) => Promise<FetchResponse<T>>;
1442
- interface FetchErrorInfo {
1443
- /** 错误信息 */
1444
- errMsg: string;
1445
+ interface RequestError extends Error {
1445
1446
  /** 错误码 */
1446
- errno: number;
1447
+ errno?: number;
1447
1448
  }
1448
- declare const mpFetch: <T extends string | ArrayBuffer | Record<never, never> | unknown[] = Record<string, any>>(url: string, { method, headers, body, cookieScope, cookieStore, ...options }?: FetchOptions<T>) => Promise<FetchResponse<T>>;
1449
- interface FetchInitOptions extends Pick<WechatMiniprogram.RequestOption, "redirect" | "enableCache" | "enableChunked" | "enableHttp2" | "enableHttpDNS" | "enableQuic" | "httpDNSServiceId" | "forceCellularNetwork" | "timeout"> {
1449
+ type RequestType = <T extends Record<never, never> | unknown[] | string | ArrayBuffer = Record<string, any>>(url: string, options?: RequestOptions<T>) => Promise<RequestResponse<T>>;
1450
+ declare const request: <T extends string | ArrayBuffer | Record<never, never> | unknown[] = Record<string, any>>(url: string, { method, headers, body, cookieScope, cookieStore, ...options }?: RequestOptions<T>) => Promise<RequestResponse<T>>;
1451
+ interface RequestInitOptions extends Pick<WechatMiniprogram.RequestOption, "redirect" | "enableCache" | "enableChunked" | "enableHttp2" | "enableHttpDNS" | "enableQuic" | "httpDNSServiceId" | "forceCellularNetwork" | "timeout"> {
1450
1452
  /**
1451
1453
  * 访问的默认域名
1452
1454
  */
@@ -1458,26 +1460,29 @@ interface FetchInitOptions extends Pick<WechatMiniprogram.RequestOption, "redire
1458
1460
  /**
1459
1461
  * 响应处理器
1460
1462
  *
1461
- * @param response 响应
1462
- * @returns 数据
1463
- * @throws {Error} 自定义的错误数据
1463
+ * @throws {RequestError} 自定义的错误数据
1464
1464
  */
1465
1465
  responseHandler?: <T extends Record<never, never> | unknown[] | string | ArrayBuffer = Record<string, any>>(
1466
1466
  /** 响应数据 */
1467
- response: FetchResponse<T>,
1467
+ response: RequestResponse<T>,
1468
1468
  /** 请求地址 */
1469
1469
  url: string,
1470
1470
  /** 请求配置 */
1471
- options: FetchOptions<T>) => FetchResponse<T>;
1471
+ options: RequestOptions<T>) => RequestResponse<T>;
1472
+ /**
1473
+ * 错误处理器
1474
+ *
1475
+ * @throws {RequestError} 自定义的错误数据
1476
+ */
1472
1477
  errorHandler?: <T extends Record<never, never> | unknown[] | string | ArrayBuffer = Record<string, any>>(
1473
1478
  /** 错误信息 */
1474
- errInfo: FetchErrorInfo,
1479
+ error: RequestError,
1475
1480
  /** 请求地址 */
1476
1481
  url: string,
1477
1482
  /** 请求配置 */
1478
- options: FetchOptions<T>) => FetchResponse<T> | never;
1483
+ options: RequestOptions<T>) => RequestResponse<T> | never;
1479
1484
  }
1480
- interface FetchFactory {
1485
+ interface RequestFactory {
1481
1486
  /**
1482
1487
  * Cookie 存储
1483
1488
  */
@@ -1485,11 +1490,11 @@ interface FetchFactory {
1485
1490
  /**
1486
1491
  * 请求方法
1487
1492
  */
1488
- fetch: FetchType;
1493
+ request: RequestType;
1489
1494
  }
1490
1495
  /**
1491
- * @param options fetch 配置选项
1496
+ * @param options request 配置选项
1492
1497
  */
1493
- declare const createMpFetch: ({ cookieStore, server, responseHandler, errorHandler, ...defaultOptions }?: FetchInitOptions) => FetchFactory;
1498
+ declare const createRequest: ({ cookieStore, server, responseHandler, errorHandler, ...defaultOptions }?: RequestInitOptions) => RequestFactory;
1494
1499
 
1495
- export { $App, $Component, $Config, $Page, type AppConfig, type AppConstructor, type AppInstance, type AppOptions, type ComponentConstructor, type ComponentInstance, type ComponentLifetimes, type ComponentOptions, Cookie, type CookieMap, CookieStore, type CookieStoreOptions, type CookieStoreType, type CookieType, Emitter, type EmitterInstance, type EventHandlerList, type EventHandlerMap, type EventType, type ExtendedAppMethods, type ExtendedComponentMethods, type ExtendedComponentProperty, type ExtendsAppOptions, type FetchBody, type FetchErrorInfo, type FetchFactory, type FetchInitOptions, type FetchOptions, type FetchResponse, type FetchType, type Handler, Headers, type HeadersInit, type PageConstructor, type PageInstance, type PageOptions, type PageQuery, type PageState, type PropType, Queue, type RefMap, type SetCookieOptions, type StorageData, type Task, type TrivialComponentInstance, type TrivialComponentOptions, type TrivialPageInstance, type TrivialPageOptions, URLSearchParams, type UrlInfo, type WildCardEventHandlerList, type WildcardHandler, check, checkAsync, createMpFetch, decode as decodeBase64, dirname, userEmitter as emitter, encode as encodeBase64, exists, fetchCookieStore, funcQueue, get, getAsync, getCookieOptions, getCookieScopeDomain, getDomain, isDir, isFile, lock, logger, ls, mkdir, mpFetch, normalizeDomain, once, parseCookieHeader, parseUrl, put, query, readFile, readJSON, remove, removeAsync, rm, saveFile, saveOnlineFile, set, setAsync, storage, take, type, unzip, wrapFunction, writeFile, writeJSON };
1500
+ export { $App, $Component, $Config, $Page, type AppConfig, type AppConstructor, type AppInstance, type AppOptions, type ComponentConstructor, type ComponentInstance, type ComponentLifetimes, type ComponentOptions, Cookie, type CookieMap, type CookieOptions, CookieStore, type CookieStoreType, type CookieType, Emitter, type EmitterInstance, type EventHandlerList, type EventHandlerMap, type EventType, type ExtendedAppMethods, type ExtendedComponentMethods, type ExtendedComponentProperty, type ExtendsAppOptions, type Handler, Headers, type HeadersInit, type PageConstructor, type PageInstance, type PageOptions, type PageQuery, type PageState, type PropType, Queue, type RefMap, type RequestBody, type RequestError, type RequestFactory, type RequestInitOptions, type RequestOptions, type RequestResponse, type RequestType, type SetCookieOptions, type StorageData, type Task, type TrivialComponentInstance, type TrivialComponentOptions, type TrivialPageInstance, type TrivialPageOptions, URLSearchParams, type UrlInfo, type WildCardEventHandlerList, type WildcardHandler, check, checkAsync, createRequest, decode as decodeBase64, dirname, userEmitter as emitter, encode as encodeBase64, exists, funcQueue, get, getAsync, getCookieOptions, getCookieScopeDomain, getDomain, isDir, isFile, isMp, isQQ, isWx, lock, logger, ls, mkdir, normalizeDomain, once, parseCookieHeader, parseUrl, put, query, readFile, readJSON, remove, removeAsync, request, requestCookieStore, rm, saveFile, saveOnlineFile, set, setAsync, storage, take, type, unzip, wrapFunction, writeFile, writeJSON };